Skip to content
Snippets Groups Projects
Commit 64621cf4 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android (Google) Code Review
Browse files

Merge "Add DynamicShortcutListPolicy::copyAllShortcuts()."

parents 648088aa 9e3082e0
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ namespace latinime { ...@@ -31,7 +31,7 @@ namespace latinime {
*/ */
class DynamicShortcutListPolicy : public DictionaryShortcutsStructurePolicy { class DynamicShortcutListPolicy : public DictionaryShortcutsStructurePolicy {
public: public:
explicit DynamicShortcutListPolicy(const BufferWithExtendableBuffer *const buffer) explicit DynamicShortcutListPolicy(BufferWithExtendableBuffer *const buffer)
: mBuffer(buffer) {} : mBuffer(buffer) {}
~DynamicShortcutListPolicy() {} ~DynamicShortcutListPolicy() {}
...@@ -82,10 +82,33 @@ class DynamicShortcutListPolicy : public DictionaryShortcutsStructurePolicy { ...@@ -82,10 +82,33 @@ class DynamicShortcutListPolicy : public DictionaryShortcutsStructurePolicy {
} }
} }
// Copy shortcuts from the shortcut list that starts at fromPos to toPos and advance these
// positions after the shortcut lists.
void copyAllShortcuts(int *const fromPos, int *const toPos) {
const bool usesAdditionalBuffer = mBuffer->isInAdditionalBuffer(*fromPos);
const uint8_t *const buffer = mBuffer->getBuffer(usesAdditionalBuffer);
if (usesAdditionalBuffer) {
*fromPos -= mBuffer->getOriginalBufferSize();
}
const int shortcutListSize = ShortcutListReadingUtils
::getShortcutListSizeAndForwardPointer(buffer, fromPos);
// Copy shortcut list size.
mBuffer->writeUintAndAdvancePosition(
shortcutListSize + ShortcutListReadingUtils::getShortcutListSizeFieldSize(),
ShortcutListReadingUtils::getShortcutListSizeFieldSize(), toPos);
for (int i = 0; i < shortcutListSize; ++i) {
const uint8_t data = ByteArrayUtils::readUint8AndAdvancePosition(buffer, fromPos);
mBuffer->writeUintAndAdvancePosition(data, 1 /* size */, toPos);
}
if (usesAdditionalBuffer) {
*fromPos += mBuffer->getOriginalBufferSize();
}
}
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicShortcutListPolicy); DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicShortcutListPolicy);
const BufferWithExtendableBuffer *const mBuffer; BufferWithExtendableBuffer *const mBuffer;
}; };
} // namespace latinime } // namespace latinime
#endif // LATINIME_DYNAMIC_SHORTCUT_LIST_POLICY_H #endif // LATINIME_DYNAMIC_SHORTCUT_LIST_POLICY_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment