diff options
author | Peng Wu <alexepico@gmail.com> | 2016-03-14 13:45:37 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2016-03-14 13:45:37 +0800 |
commit | 312eb6bb3212ed3aceef1daaadfe3e7d5554c95a (patch) | |
tree | f321a2448d78f2b5563756e6cf04a25aad432ce9 /src | |
parent | 0a229eec709ba7a1da94d7885fe73acfeb1b2047 (diff) | |
download | libpinyin-312eb6bb3212ed3aceef1daaadfe3e7d5554c95a.tar.gz libpinyin-312eb6bb3212ed3aceef1daaadfe3e7d5554c95a.tar.xz libpinyin-312eb6bb3212ed3aceef1daaadfe3e7d5554c95a.zip |
write fini_entries method
Diffstat (limited to 'src')
-rw-r--r-- | src/storage/chewing_large_table2_bdb.cpp | 84 | ||||
-rw-r--r-- | src/storage/chewing_large_table2_bdb.h | 2 |
2 files changed, 47 insertions, 39 deletions
diff --git a/src/storage/chewing_large_table2_bdb.cpp b/src/storage/chewing_large_table2_bdb.cpp index ba0b88b..8bd47f3 100644 --- a/src/storage/chewing_large_table2_bdb.cpp +++ b/src/storage/chewing_large_table2_bdb.cpp @@ -79,6 +79,50 @@ void ChewingLargeTable2::init_entries() { #undef CASE } +void ChewingLargeTable2::fini_entries() { + assert(NULL != m_entries); + + assert(MAX_PHRASE_LENGTH + 1 == m_entries->len); + + for (size_t i = 1; i < m_entries->len; i++) { + +#define CASE(len) case len: \ + { \ + ChewingTableEntry<len> * entry = \ + (ChewingTableEntry<len> *) \ + g_ptr_array_index(m_entries, len); \ + delete entry; \ + } + + switch(i) { + CASE(1); + CASE(2); + CASE(3); + CASE(4); + CASE(5); + CASE(6); + CASE(7); + CASE(8); + CASE(9); + CASE(10); + CASE(11); + CASE(12); + CASE(13); + CASE(14); + CASE(15); + CASE(16); + default: + assert(false); + } + +#undef CASE + + } + + g_ptr_array_free(m_entries, TRUE); + m_entries = NULL; +} + void ChewingLargeTable2::reset() { if (m_db) { m_db->sync(m_db, 0); @@ -86,45 +130,7 @@ void ChewingLargeTable2::reset() { m_db = NULL; } -#define CASE(len) case len: \ - { \ - ChewingTableEntry<len> * entry = \ - (ChewingTableEntry<len> *) \ - g_ptr_array_index(m_entries, len); \ - delete entry; \ - } - - if (m_entries) { - assert(MAX_PHRASE_LENGTH + 1 == m_entries->len); - - for (size_t i = 1; i < m_entries->len; i++) { - switch(i) { - CASE(1); - CASE(2); - CASE(3); - CASE(4); - CASE(5); - CASE(6); - CASE(7); - CASE(8); - CASE(9); - CASE(10); - CASE(11); - CASE(12); - CASE(13); - CASE(14); - CASE(15); - CASE(16); - default: - assert(false); - } - } - - g_ptr_array_free(m_entries, TRUE); - m_entries = NULL; - } - -#undef CASE + fini_entries(); } /* attach method */ diff --git a/src/storage/chewing_large_table2_bdb.h b/src/storage/chewing_large_table2_bdb.h index 5961dbd..5a2f84d 100644 --- a/src/storage/chewing_large_table2_bdb.h +++ b/src/storage/chewing_large_table2_bdb.h @@ -43,6 +43,8 @@ protected: void init_entries(); + void fini_entries(); + void reset(); protected: |