@@ -38,8 +38,8 @@ bool TArscRichString::operator<(const TArscRichString& _other) const
3838
3939QStringPool* g_publicStrPool;
4040
41- QStringPool::QStringPool (bool _removeUnuse, QObject* _parent)
42- : QObject(_parent), m_removeUnuse(_removeUnuse), m_stringPoolHeader()
41+ QStringPool::QStringPool (const QString& _name, bool _removeUnuse, QObject* _parent)
42+ : QObject(_parent), m_name(_name), m_removeUnuse(_removeUnuse), m_stringPoolHeader()
4343 , m_strings(ArscRichStringLessThanFuncWrapper(&styleFirstLessThan))
4444 , m_string_to_guid(ArscRichStringLessThanFuncWrapper(&strongLessThan))
4545 // m_strings(styleFirstLessThan), m_string_to_guid(strongLessThan)
@@ -99,14 +99,44 @@ void QStringPool::readBuff(const char* _buff)
9999 t_pStyleBuff += sizeof (ResStringPool_span);
100100 }
101101 }
102+ // -----------查找重复的字符串---------------------------------
103+ ArscRichStringLessThanFuncWrapper t_funcWrapper (&strongLessThan);
104+ ArscRichStringMap t_string_to_guid (t_funcWrapper);
102105 for (QVector<PArscRichString>::iterator i = t_strings.begin (); i != t_strings.end (); ++i)
103106 {
107+ ArscRichStringMap::iterator t_findIt = t_string_to_guid.find (*i);
108+ if (t_findIt != t_string_to_guid.end ())
109+ {
110+ qDebug () << Qt::hex << Qt::showbase << m_name << " duplicate string:" << (*i)->string << " guid:" << (*i)->guid << " ->" << (t_findIt->second );
111+ m_repeat_string_guid_map.insert ((*i)->guid , t_findIt->second );
112+ continue ;
113+ }
114+ t_string_to_guid.insert (ArscRichStringMap::value_type (*i, (*i)->guid ));
115+ }
116+ for (QVector<PArscRichString>::iterator i = t_strings.begin (); i != t_strings.end (); ++i)
117+ {
118+ PArscRichString& t_pArscRichString = *i;
119+ for (int j = 0 ; j < t_pArscRichString->styles .count (); ++j)
120+ {
121+ int t_oldGuid = t_pArscRichString->styles [j].ref ->guid ;
122+ if (m_repeat_string_guid_map.find (t_oldGuid) != m_repeat_string_guid_map.end ())
123+ {
124+ int t_newGuid = m_repeat_string_guid_map.value (t_oldGuid);
125+ t_pArscRichString->styles [j].ref ->guid = t_newGuid;
126+ }
127+ }
128+ }
129+ // -----------填充字符串池---------------------------------
130+ for (QVector<PArscRichString>::iterator i = t_strings.begin (); i != t_strings.end (); ++i)
131+ {
132+ if (m_string_to_guid.find (*i) != m_string_to_guid.end ())
133+ continue ;
104134 m_strings.insert (ArscRichStringMap::value_type (*i, (*i)->guid ));
105135 m_guid_to_string.insert ((*i)->guid , *i);
106136 // 理论上,同样的字符串不应该重复出现。但是结果某些工具(比如AntiSplit-M)处理的,可能出现这个问题。
107- Q_ASSERT (m_string_to_guid.find (*i) == m_string_to_guid.end ());
108137 m_string_to_guid.insert (ArscRichStringMap::value_type (*i, (*i)->guid ));
109138 }
139+ m_stringPoolHeader.stringCount -= m_repeat_string_guid_map.size ();
110140 t_strings.clear ();
111141}
112142void QStringPool::writeBuff (QByteArray& _buff)
@@ -198,6 +228,14 @@ bool QStringPool::strongLessThan(const PArscRichString& _p1, const PArscRichStri
198228PArscRichString QStringPool::getGuidRef (uint32_t _guid) const
199229{
200230 QMap<int , PArscRichString>::const_iterator t_pIter = m_guid_to_string.find (_guid);
231+ if (t_pIter == m_guid_to_string.end ())
232+ {
233+ QMap<int , int >::const_iterator t_repeatIter = m_repeat_string_guid_map.find (_guid);
234+ if (t_repeatIter != m_repeat_string_guid_map.end ())
235+ {
236+ t_pIter = m_guid_to_string.find (t_repeatIter.value ());
237+ }
238+ }
201239 return (t_pIter == m_guid_to_string.end ()) ? PArscRichString () : t_pIter.value ();
202240}
203241uint32_t QStringPool::getRefIndex (const PArscRichString& _s) const
0 commit comments