refine retrieve_divided_item
authorPeng Wu <alexepico@gmail.com>
Thu, 19 Apr 2012 06:51:00 +0000 (14:51 +0800)
committerPeng Wu <alexepico@gmail.com>
Thu, 19 Apr 2012 06:51:00 +0000 (14:51 +0800)
src/pinyin.cpp
src/storage/pinyin_parser2.cpp
src/storage/pinyin_parser2.h

index 7318d44..0fd52e9 100644 (file)
@@ -731,6 +731,10 @@ static bool _try_divided_table(pinyin_instance_t * instance,
     ChewingKeyVector & pinyin_keys = instance->m_pinyin_keys;
     ChewingKeyRestVector & pinyin_key_rests = instance->m_pinyin_key_rests;
 
+    assert(pinyin_keys->len == pinyin_key_rests->len);
+    gint num_keys = pinyin_keys->len;
+    assert(offset < num_keys);
+
     /* handle "^xian$" -> "xi'an" here */
     ChewingKey * key = &g_array_index(pinyin_keys, ChewingKey, offset);
     ChewingKeyRest * rest = &g_array_index(pinyin_key_rests,
@@ -750,8 +754,7 @@ static bool _try_divided_table(pinyin_instance_t * instance,
     }
 
     item = context->m_full_pinyin_parser->retrieve_divided_item
-        (options, offset, pinyin_keys, pinyin_key_rests,
-         instance->m_raw_full_pinyin,
+        (options, key, rest, instance->m_raw_full_pinyin,
          strlen(instance->m_raw_full_pinyin));
 
     if (item) {
index b4175b1..e9e5347 100644 (file)
@@ -574,17 +574,8 @@ bool FullPinyinParser2::post_process2(pinyin_option_t options,
 }
 
 const divided_table_item_t * FullPinyinParser2::retrieve_divided_item
-(pinyin_option_t options, size_t offset,
- ChewingKeyVector & keys, ChewingKeyRestVector & key_rests,
+(pinyin_option_t options, ChewingKey * key, ChewingKeyRest * rest,
  const char * str, int len) const {
-    assert(keys->len == key_rests->len);
-
-    gint num_keys = keys->len;
-    assert(offset < num_keys);
-
-    ChewingKey * key = &g_array_index(keys, ChewingKey, offset);
-    ChewingKeyRest * rest = &g_array_index(key_rests,
-                                           ChewingKeyRest, offset);
     guint16 tone = CHEWING_ZERO_TONE;
 
     /* lookup divided table */
index 77ed3d4..50bcef0 100644 (file)
@@ -153,8 +153,7 @@ protected:
 
 public:
     const divided_table_item_t * retrieve_divided_item
-    (pinyin_option_t options, size_t offset,
-     ChewingKeyVector & keys, ChewingKeyRestVector & key_rests,
+    (pinyin_option_t options, ChewingKey * key, ChewingKeyRest * rest,
      const char * str, int len) const;
 public:
     FullPinyinParser2();