summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2010-08-16 13:50:50 +0800
committerPeng Wu <alexepico@gmail.com>2010-08-16 13:50:50 +0800
commit1b0c733a6596c8f3250e847ea2d92cd7a32000ae (patch)
tree5a1810e5ecef56d54bb6141b3db0739101d5e347 /src
parentfe5d37164a6274180843234a3b959c59f0763582 (diff)
downloadlibpinyin-1b0c733a6596c8f3250e847ea2d92cd7a32000ae.tar.gz
libpinyin-1b0c733a6596c8f3250e847ea2d92cd7a32000ae.tar.xz
libpinyin-1b0c733a6596c8f3250e847ea2d92cd7a32000ae.zip
re-factor remove_phrase_item.
Diffstat (limited to 'src')
-rw-r--r--src/storage/phrase_index.cpp27
1 files changed, 5 insertions, 22 deletions
diff --git a/src/storage/phrase_index.cpp b/src/storage/phrase_index.cpp
index 188421a..f87d834 100644
--- a/src/storage/phrase_index.cpp
+++ b/src/storage/phrase_index.cpp
@@ -154,32 +154,15 @@ bool SubPhraseIndex::add_phrase_item(phrase_token_t token, PhraseItem * item){
}
bool SubPhraseIndex::remove_phrase_item(phrase_token_t token, PhraseItem * & item){
- table_offset_t offset;
- guint8 phrase_length;
- guint8 n_prons;
-
- bool result = m_phrase_index.get_content
- ((token & PHRASE_MASK)
- * sizeof(table_offset_t), &offset, sizeof(table_offset_t));
-
- if ( !result )
- return result;
-
- if ( 0 == offset )
- return false;
+ PhraseItem old_item;
- result = m_phrase_content.get_content(offset, &phrase_length, sizeof(guint8));
- if ( !result )
- return result;
+ int result = get_phrase_item(token, old_item);
+ if (!result)
+ return result;
- result = m_phrase_content.get_content(offset+sizeof(guint8), &n_prons, sizeof(guint8));
- if ( !result )
- return result;
-
- size_t length = phrase_item_header + phrase_length * sizeof ( utf16_t ) + n_prons * ( phrase_length * sizeof (PinyinKey) + sizeof(guint32) );
item = new PhraseItem;
//implictly copy data from m_chunk_content.
- item->m_chunk.set_content(0, (char *) m_phrase_content.begin() + offset, length);
+ item->m_chunk.set_content(0, (char *) old_item.m_chunk.begin() , old_item.m_chunk.size());
const table_offset_t zero_const = 0;
m_phrase_index.set_content((token & PHRASE_MASK)