Use memmove for all place src and dest can be same.

Change-Id: I03e5c8f95cb22c7096ff545f1181f914b80a6c58
This commit is contained in:
Keisuke Kuroyanagi 2014-01-20 11:27:01 -08:00
parent b1814c9633
commit 3e0777e726
4 changed files with 9 additions and 9 deletions

View file

@ -118,7 +118,7 @@ namespace latinime {
actualLength0 = i + 1; actualLength0 = i + 1;
} }
actualLength0 = min(actualLength0, MAX_WORD_LENGTH); actualLength0 = min(actualLength0, MAX_WORD_LENGTH);
memcpy(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;
} }
@ -130,7 +130,7 @@ namespace latinime {
actualLength1 = i + 1; actualLength1 = i + 1;
} }
actualLength1 = min(actualLength1, MAX_WORD_LENGTH - actualLength0); actualLength1 = min(actualLength1, MAX_WORD_LENGTH - actualLength0);
memcpy(&dest[actualLength0], src1, actualLength1 * sizeof(dest[0])); memmove(&dest[actualLength0], src1, actualLength1 * sizeof(dest[0]));
return actualLength0 + actualLength1; return actualLength0 + actualLength1;
} }
} // namespace latinime } // namespace latinime

View file

@ -17,7 +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 <cstring> // for memcpy() #include <cstring> // for memmove()
#include <stdint.h> #include <stdint.h>
#include "defines.h" #include "defines.h"
@ -38,7 +38,7 @@ class DicNodeStateOutput {
} }
void init(const DicNodeStateOutput *const stateOutput) { void init(const DicNodeStateOutput *const stateOutput) {
memcpy(mCodePointsBuf, stateOutput->mCodePointsBuf, memmove(mCodePointsBuf, stateOutput->mCodePointsBuf,
stateOutput->mOutputtedCodePointCount * sizeof(mCodePointsBuf[0])); stateOutput->mOutputtedCodePointCount * sizeof(mCodePointsBuf[0]));
mOutputtedCodePointCount = stateOutput->mOutputtedCodePointCount; mOutputtedCodePointCount = stateOutput->mOutputtedCodePointCount;
if (mOutputtedCodePointCount < MAX_WORD_LENGTH) { if (mOutputtedCodePointCount < MAX_WORD_LENGTH) {
@ -51,7 +51,7 @@ class DicNodeStateOutput {
if (mergedNodeCodePoints) { if (mergedNodeCodePoints) {
const int additionalCodePointCount = min(static_cast<int>(mergedNodeCodePointCount), const int additionalCodePointCount = min(static_cast<int>(mergedNodeCodePointCount),
MAX_WORD_LENGTH - mOutputtedCodePointCount); MAX_WORD_LENGTH - mOutputtedCodePointCount);
memcpy(&mCodePointsBuf[mOutputtedCodePointCount], mergedNodeCodePoints, memmove(&mCodePointsBuf[mOutputtedCodePointCount], mergedNodeCodePoints,
additionalCodePointCount * sizeof(mCodePointsBuf[0])); additionalCodePointCount * sizeof(mCodePointsBuf[0]));
mOutputtedCodePointCount = static_cast<uint16_t>( mOutputtedCodePointCount = static_cast<uint16_t>(
mOutputtedCodePointCount + mergedNodeCodePointCount); mOutputtedCodePointCount + mergedNodeCodePointCount);

View file

@ -17,7 +17,7 @@
#ifndef LATINIME_DIC_NODE_STATE_PREVWORD_H #ifndef LATINIME_DIC_NODE_STATE_PREVWORD_H
#define LATINIME_DIC_NODE_STATE_PREVWORD_H #define LATINIME_DIC_NODE_STATE_PREVWORD_H
#include <cstring> // for memset() #include <cstring> // for memset() and memmove()
#include <stdint.h> #include <stdint.h>
#include "defines.h" #include "defines.h"
@ -62,7 +62,7 @@ class DicNodeStatePrevWord {
mPrevWordProbability = prevWord->mPrevWordProbability; mPrevWordProbability = prevWord->mPrevWordProbability;
mPrevWordPtNodePos = prevWord->mPrevWordPtNodePos; mPrevWordPtNodePos = prevWord->mPrevWordPtNodePos;
mSecondWordFirstInputIndex = prevWord->mSecondWordFirstInputIndex; mSecondWordFirstInputIndex = prevWord->mSecondWordFirstInputIndex;
memcpy(mPrevWord, prevWord->mPrevWord, prevWord->mPrevWordLength * sizeof(mPrevWord[0])); memmove(mPrevWord, prevWord->mPrevWord, prevWord->mPrevWordLength * sizeof(mPrevWord[0]));
} }
void init(const int16_t prevWordCount, const int16_t prevWordProbability, void init(const int16_t prevWordCount, const int16_t prevWordProbability,

View file

@ -18,7 +18,7 @@
#include "suggest/core/layout/proximity_info_state.h" #include "suggest/core/layout/proximity_info_state.h"
#include <cstring> // for memset() and memcpy() #include <cstring> // for memset() and memmove()
#include <sstream> // for debug prints #include <sstream> // for debug prints
#include <vector> #include <vector>
@ -285,7 +285,7 @@ float ProximityInfoState::getDirection(const int index0, const int index1) const
} }
float ProximityInfoState::getMostProbableString(int *const codePointBuf) const { float ProximityInfoState::getMostProbableString(int *const codePointBuf) const {
memcpy(codePointBuf, mMostProbableString, sizeof(mMostProbableString)); memmove(codePointBuf, mMostProbableString, sizeof(mMostProbableString));
return mMostProbableStringProbability; return mMostProbableStringProbability;
} }