summaryrefslogtreecommitdiffstats
path: root/src/storage/chewing_large_table2_bdb.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-03-14 13:45:37 +0800
committerPeng Wu <alexepico@gmail.com>2016-03-14 13:45:37 +0800
commit312eb6bb3212ed3aceef1daaadfe3e7d5554c95a (patch)
treef321a2448d78f2b5563756e6cf04a25aad432ce9 /src/storage/chewing_large_table2_bdb.cpp
parent0a229eec709ba7a1da94d7885fe73acfeb1b2047 (diff)
downloadlibpinyin-312eb6bb3212ed3aceef1daaadfe3e7d5554c95a.tar.gz
libpinyin-312eb6bb3212ed3aceef1daaadfe3e7d5554c95a.tar.xz
libpinyin-312eb6bb3212ed3aceef1daaadfe3e7d5554c95a.zip
write fini_entries method
Diffstat (limited to 'src/storage/chewing_large_table2_bdb.cpp')
-rw-r--r--src/storage/chewing_large_table2_bdb.cpp84
1 files changed, 45 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 */