Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf612a3a authored by Ken Wakasa's avatar Ken Wakasa
Browse files

Use std::min() and std::max()

Change-Id: I2992fa16692ace2a6febedc4393812faf763638f
parent eba0af12
Loading
Loading
Loading
Loading
+0 −3
Original line number Original line Diff line number Diff line
@@ -344,9 +344,6 @@ static inline void prof_out(void) {
#define MAX_POINTER_COUNT 1
#define MAX_POINTER_COUNT 1
#define MAX_POINTER_COUNT_G 2
#define MAX_POINTER_COUNT_G 2


template<typename T> AK_FORCE_INLINE const T &min(const T &a, const T &b) { return a < b ? a : b; }
template<typename T> AK_FORCE_INLINE const T &max(const T &a, const T &b) { return a > b ? a : b; }

// DEBUG
// DEBUG
#define INPUTLENGTH_FOR_DEBUG (-1)
#define INPUTLENGTH_FOR_DEBUG (-1)
#define MIN_OUTPUT_INDEX_FOR_DEBUG (-1)
#define MIN_OUTPUT_INDEX_FOR_DEBUG (-1)
+2 −1
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef LATINIME_DIC_NODE_PRIORITY_QUEUE_H
#ifndef LATINIME_DIC_NODE_PRIORITY_QUEUE_H
#define LATINIME_DIC_NODE_PRIORITY_QUEUE_H
#define LATINIME_DIC_NODE_PRIORITY_QUEUE_H


#include <algorithm>
#include <queue>
#include <queue>
#include <vector>
#include <vector>


@@ -49,7 +50,7 @@ class DicNodePriorityQueue : public DicNodeReleaseListener {


    AK_FORCE_INLINE void setMaxSize(const int maxSize) {
    AK_FORCE_INLINE void setMaxSize(const int maxSize) {
        ASSERT(maxSize <= mCapacity);
        ASSERT(maxSize <= mCapacity);
        mMaxSize = min(maxSize, mCapacity);
        mMaxSize = std::min(maxSize, mCapacity);
    }
    }


    AK_FORCE_INLINE void clearAndResizeToCapacity() {
    AK_FORCE_INLINE void clearAndResizeToCapacity() {
+3 −2
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


#include "suggest/core/dicnode/dic_node_utils.h"
#include "suggest/core/dicnode/dic_node_utils.h"


#include <algorithm>
#include <cstring>
#include <cstring>


#include "suggest/core/dicnode/dic_node.h"
#include "suggest/core/dicnode/dic_node.h"
@@ -117,7 +118,7 @@ namespace latinime {
        }
        }
        actualLength0 = i + 1;
        actualLength0 = i + 1;
    }
    }
    actualLength0 = min(actualLength0, MAX_WORD_LENGTH);
    actualLength0 = std::min(actualLength0, MAX_WORD_LENGTH);
    memmove(dest, src0, actualLength0 * sizeof(dest[0]));
    memmove(dest, src0, actualLength0 * sizeof(dest[0]));
    if (!src1 || length1 == 0) {
    if (!src1 || length1 == 0) {
        return actualLength0;
        return actualLength0;
@@ -129,7 +130,7 @@ namespace latinime {
        }
        }
        actualLength1 = i + 1;
        actualLength1 = i + 1;
    }
    }
    actualLength1 = min(actualLength1, MAX_WORD_LENGTH - actualLength0);
    actualLength1 = std::min(actualLength1, MAX_WORD_LENGTH - actualLength0);
    memmove(&dest[actualLength0], src1, actualLength1 * sizeof(dest[0]));
    memmove(&dest[actualLength0], src1, actualLength1 * sizeof(dest[0]));
    return actualLength0 + actualLength1;
    return actualLength0 + actualLength1;
}
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef LATINIME_DIC_NODES_CACHE_H
#ifndef LATINIME_DIC_NODES_CACHE_H
#define LATINIME_DIC_NODES_CACHE_H
#define LATINIME_DIC_NODES_CACHE_H


#include <algorithm>
#include <stdint.h>
#include <stdint.h>


#include "defines.h"
#include "defines.h"
@@ -51,7 +52,7 @@ class DicNodesCache {
        // We want to use the max capacity for the current active dic node queue.
        // We want to use the max capacity for the current active dic node queue.
        mActiveDicNodes->clearAndResizeToCapacity();
        mActiveDicNodes->clearAndResizeToCapacity();
        // nextActiveSize is used to limit the next iteration's active dic node size.
        // nextActiveSize is used to limit the next iteration's active dic node size.
        const int nextActiveSizeFittingToTheCapacity = min(nextActiveSize, getCacheCapacity());
        const int nextActiveSizeFittingToTheCapacity = std::min(nextActiveSize, getCacheCapacity());
        mNextActiveDicNodes->clearAndResize(nextActiveSizeFittingToTheCapacity);
        mNextActiveDicNodes->clearAndResize(nextActiveSizeFittingToTheCapacity);
        mTerminalDicNodes->clearAndResize(terminalSize);
        mTerminalDicNodes->clearAndResize(terminalSize);
        // We want to use the max capacity for the cached dic nodes that will be used for the
        // We want to use the max capacity for the cached dic nodes that will be used for the
+3 −1
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef LATINIME_DIC_NODE_STATE_OUTPUT_H
#ifndef LATINIME_DIC_NODE_STATE_OUTPUT_H
#define LATINIME_DIC_NODE_STATE_OUTPUT_H
#define LATINIME_DIC_NODE_STATE_OUTPUT_H


#include <algorithm>
#include <cstring> // for memmove()
#include <cstring> // for memmove()
#include <stdint.h>
#include <stdint.h>


@@ -49,7 +50,8 @@ class DicNodeStateOutput {
    void addMergedNodeCodePoints(const uint16_t mergedNodeCodePointCount,
    void addMergedNodeCodePoints(const uint16_t mergedNodeCodePointCount,
            const int *const mergedNodeCodePoints) {
            const int *const mergedNodeCodePoints) {
        if (mergedNodeCodePoints) {
        if (mergedNodeCodePoints) {
            const int additionalCodePointCount = min(static_cast<int>(mergedNodeCodePointCount),
            const int additionalCodePointCount = std::min(
                    static_cast<int>(mergedNodeCodePointCount),
                    MAX_WORD_LENGTH - mOutputtedCodePointCount);
                    MAX_WORD_LENGTH - mOutputtedCodePointCount);
            memmove(&mCodePointsBuf[mOutputtedCodePointCount], mergedNodeCodePoints,
            memmove(&mCodePointsBuf[mOutputtedCodePointCount], mergedNodeCodePoints,
                    additionalCodePointCount * sizeof(mCodePointsBuf[0]));
                    additionalCodePointCount * sizeof(mCodePointsBuf[0]));
Loading