From 1496b0a56bbd45cdafa44934a73e026b19593dae Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Thu, 8 Apr 2010 18:29:59 +0800 Subject: [PATCH] Does not use Array anymore --- src/Database.cc | 2 +- src/DoublePinyinEditor.cc | 14 +++++++------- src/FullPinyinEditor.cc | 8 ++++---- src/PhraseArray.h | 4 ++-- src/PhraseEditor.cc | 14 ++++++++------ src/PhraseEditor.h | 13 +++++++------ src/PinyinArray.h | 9 ++++++--- src/PinyinParser.cc | 2 +- src/WideString.h | 5 +++-- 9 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/Database.cc b/src/Database.cc index 568e451..ac09888 100644 --- a/src/Database.cc +++ b/src/Database.cc @@ -148,7 +148,7 @@ Query::fill (PhraseArray &phrases, gint count) phrase.pinyin_id[i][0] = m_stmt->columnInt (column++); phrase.pinyin_id[i][1] = m_stmt->columnInt (column++); } - phrases << phrase; + phrases.push_back (phrase); row ++; if (G_UNLIKELY (row == count)) { return row; diff --git a/src/DoublePinyinEditor.cc b/src/DoublePinyinEditor.cc index bded785..fbfcc21 100644 --- a/src/DoublePinyinEditor.cc +++ b/src/DoublePinyinEditor.cc @@ -111,7 +111,7 @@ DoublePinyinEditor::removeWordBefore (void) } else { m_pinyin_len = m_pinyin.back ().begin; - m_pinyin.pop (); + m_pinyin.pop_back (); m_text.erase (m_pinyin_len, m_cursor - m_pinyin_len); m_cursor = m_pinyin_len; updatePhraseEditor (); @@ -190,7 +190,7 @@ DoublePinyinEditor::moveCursorLeftByWord (void) } else { m_cursor = m_pinyin_len = m_pinyin.back ().begin; - m_pinyin.pop (); + m_pinyin.pop_back (); updatePhraseEditor (); update (); } @@ -211,7 +211,7 @@ DoublePinyinEditor::moveCursorToBegin (void) return FALSE; m_cursor = 0; - m_pinyin.removeAll (); + m_pinyin.clear (); m_pinyin_len = 0; updatePhraseEditor (); update (); @@ -245,7 +245,7 @@ DoublePinyinEditor::reset (void) m_pinyin.empty () == FALSE) { m_cursor = 0; m_text.truncate (0); - m_pinyin.removeAll (); + m_pinyin.clear (); m_pinyin_len = 0; updatePhraseEditor (); update (); @@ -296,7 +296,7 @@ DoublePinyinEditor::updatePinyin (gboolean all) if (all && (m_pinyin_len != 0 || !m_pinyin.empty ())) { - m_pinyin.removeAll (); + m_pinyin.clear (); m_pinyin_len = 0; retval = TRUE; } @@ -305,7 +305,7 @@ DoublePinyinEditor::updatePinyin (gboolean all) retval = TRUE; while (m_pinyin_len > m_cursor) { m_pinyin_len = m_pinyin.back ().begin; - m_pinyin.pop (); + m_pinyin.pop_back (); } } @@ -319,7 +319,7 @@ DoublePinyinEditor::updatePinyin (gboolean all) m_pinyin.back ()->flags & PINYIN_INCOMPLETE_PINYIN) { const Pinyin *pinyin = isPinyin (ID (m_text[m_pinyin_len -1]),ID (m_text[m_pinyin_len])); if (pinyin) { - m_pinyin.pop (); + m_pinyin.pop_back (); m_pinyin.append (pinyin, m_pinyin_len - 1, 2); m_pinyin_len += 1; } diff --git a/src/FullPinyinEditor.cc b/src/FullPinyinEditor.cc index 6c806c1..e7fdd9b 100644 --- a/src/FullPinyinEditor.cc +++ b/src/FullPinyinEditor.cc @@ -95,7 +95,7 @@ FullPinyinEditor::removeWordBefore (void) const Pinyin & p = *m_pinyin.back (); cursor = m_cursor - p.len; m_pinyin_len -= p.len; - m_pinyin.pop (); + m_pinyin.pop_back (); } m_text.erase (cursor, m_cursor - cursor); @@ -156,7 +156,7 @@ FullPinyinEditor::moveCursorLeftByWord (void) const Pinyin & p = *m_pinyin.back (); m_cursor -= p.len; m_pinyin_len -= p.len; - m_pinyin.pop (); + m_pinyin.pop_back (); updatePhraseEditor (); update (); @@ -177,7 +177,7 @@ FullPinyinEditor::moveCursorToBegin (void) return FALSE; m_cursor = 0; - m_pinyin.removeAll (); + m_pinyin.clear (); m_pinyin_len = 0; updatePhraseEditor (); @@ -202,7 +202,7 @@ void FullPinyinEditor::updatePinyin (void) { if (G_UNLIKELY (m_text.empty ())) { - m_pinyin.removeAll (); + m_pinyin.clear (); m_pinyin_len = 0; } else { diff --git a/src/PhraseArray.h b/src/PhraseArray.h index 47fa505..c378232 100644 --- a/src/PhraseArray.h +++ b/src/PhraseArray.h @@ -1,12 +1,12 @@ #ifndef __PY_PHRASE_ARRAY_H_ #define __PY_PHRASE_ARRAY_H_ +#include #include "Phrase.h" -#include "Array.h" namespace PY { -typedef Array PhraseArray; +typedef std::vector PhraseArray; }; diff --git a/src/PhraseEditor.cc b/src/PhraseEditor.cc index 8dab885..7584a03 100644 --- a/src/PhraseEditor.cc +++ b/src/PhraseEditor.cc @@ -34,7 +34,7 @@ PhraseEditor::update (const PinyinArray &pinyin) m_cursor = 0; /* FIXME, should not remove all phrases1 */ - m_selected_phrases.removeAll (); + m_selected_phrases.clear (); m_selected_string.truncate (0); updateCandidates (); return TRUE; @@ -56,7 +56,9 @@ PhraseEditor::selectCandidate (guint i) return FALSE; if (G_LIKELY (i == 0)) { - m_selected_phrases << m_candidate_0_phrases; + m_selected_phrases.insert (m_selected_phrases.end (), + m_candidate_0_phrases.begin (), + m_candidate_0_phrases.end ()); if (G_LIKELY (m_props.modeSimp ())) m_selected_string << m_candidates[0].phrase; else @@ -64,7 +66,7 @@ PhraseEditor::selectCandidate (guint i) m_cursor = m_pinyin.size (); } else { - m_selected_phrases << m_candidates[i]; + m_selected_phrases.push_back (m_candidates[i]); if (G_LIKELY (m_props.modeSimp ())) m_selected_string << m_candidates[i].phrase; else @@ -79,7 +81,7 @@ PhraseEditor::selectCandidate (guint i) void PhraseEditor::updateCandidates (void) { - m_candidates.removeAll (); + m_candidates.clear (); updateTheFirstCandidate (); if (m_query) { delete m_query; @@ -94,7 +96,7 @@ PhraseEditor::updateCandidates (void) phrase.reset (); for (guint i = 0; i < m_candidate_0_phrases.size (); i++) phrase += m_candidate_0_phrases[i]; - m_candidates << phrase; + m_candidates.push_back (phrase); } m_query = new Query (m_database, @@ -111,7 +113,7 @@ PhraseEditor::updateTheFirstCandidate (void) guint begin; guint end; - m_candidate_0_phrases.removeAll (); + m_candidate_0_phrases.clear (); if (G_UNLIKELY (m_pinyin.size () == 0)) return; diff --git a/src/PhraseEditor.h b/src/PhraseEditor.h index dde2b36..acb3aad 100644 --- a/src/PhraseEditor.h +++ b/src/PhraseEditor.h @@ -57,7 +57,7 @@ public: return FALSE; } else { - m_selected_phrases.removeAll (); + m_selected_phrases.clear (); m_selected_string.truncate (0); m_cursor = 0; updateCandidates (); @@ -66,11 +66,11 @@ public: } void reset (void) { - m_candidates.removeAll (); - m_selected_phrases.removeAll (); + m_candidates.clear (); + m_selected_phrases.clear (); m_selected_string.truncate (0); - m_candidate_0_phrases.removeAll (); - m_pinyin.removeAll (); + m_candidate_0_phrases.clear (); + m_pinyin.clear (); m_cursor = 0; if (m_query) { delete m_query; @@ -82,7 +82,8 @@ public: gboolean selectCandidate (guint i); gboolean resetCandidate (guint i); void commit (void) { - m_selected_phrases << m_candidate_0_phrases; + m_selected_phrases.insert (m_selected_phrases.end (), + m_candidate_0_phrases.begin (), m_candidate_0_phrases.end ()); m_database.commit (m_selected_phrases); reset (); } diff --git a/src/PinyinArray.h b/src/PinyinArray.h index c02c5d6..fa70c79 100644 --- a/src/PinyinArray.h +++ b/src/PinyinArray.h @@ -1,8 +1,8 @@ #ifndef __PY_PINYIN_ARRAY_H_ #define __PY_PINYIN_ARRAY_H_ +#include #include "Types.h" -#include "Array.h" namespace PY { @@ -31,9 +31,12 @@ struct PinyinSegment { } }; -class PinyinArray: public Array { +class PinyinArray: public std::vector { public: - PinyinArray (guint init_size = 0) : Array (init_size) {} + PinyinArray (guint init_size = 0) { + std::vector::reserve (init_size); + } + void append (const Pinyin *pinyin, guint begin, guint len) { push_back (PinyinSegment (pinyin, begin, len)); } diff --git a/src/PinyinParser.cc b/src/PinyinParser.cc index ef8906f..ee59047 100644 --- a/src/PinyinParser.cc +++ b/src/PinyinParser.cc @@ -113,7 +113,7 @@ PinyinParser::parse (const String &pinyin, const Pinyin *prev_py; gchar prev_c; - result.removeAll (); + result.clear (); if (G_UNLIKELY (len < 0)) len = pinyin.size (); diff --git a/src/WideString.h b/src/WideString.h index 5518910..124a00d 100644 --- a/src/WideString.h +++ b/src/WideString.h @@ -1,12 +1,13 @@ #ifndef __PY_WIDE_STRING_H_ #define __PY_WIDE_STRING_H_ + +#if 0 #include #include #include "Array.h" namespace PY { -#if 0 class WideString { public: WideString (const gchar *init) : m_string (g_utf8_strlen (init, -1) + 1) { @@ -101,6 +102,6 @@ public: private: Array m_string; }; -#endif }; #endif +#endif -- 2.7.4