diff options
author | Monroe Linden <monroe@lindenlab.com> | 2010-02-17 18:18:18 -0800 |
---|---|---|
committer | Monroe Linden <monroe@lindenlab.com> | 2010-02-17 18:18:18 -0800 |
commit | 3e8320201fb89ce01bed18dc1ab7a41811fd3982 (patch) | |
tree | d4c18c6f1e6e4f271e95efc4cda3d4ab24dad8a6 /indra/llui/llkeywords.h | |
parent | d742b3e91182860d411fb18f1041150442766189 (diff) |
Partial fix for EXT-5071.
Changed the index on the keyword map in LLKeywords so that LLKeywords::findSegments() doesn't have to create LLWString objects to search the map.
Reviewed by Richard.
Diffstat (limited to 'indra/llui/llkeywords.h')
-rw-r--r-- | indra/llui/llkeywords.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/indra/llui/llkeywords.h b/indra/llui/llkeywords.h index 53377869ca..e5b66dfa56 100644 --- a/indra/llui/llkeywords.h +++ b/indra/llui/llkeywords.h @@ -92,8 +92,33 @@ public: const std::string& key, const LLColor3& color, const std::string& tool_tip = LLStringUtil::null); - - typedef std::map<LLWString, LLKeywordToken*> word_token_map_t; + + // This class is here as a performance optimization. + // The word token map used to be defined as std::map<LLWString, LLKeywordToken*>. + // This worked, but caused a performance bottleneck due to memory allocation and string copies + // because it's not possible to search such a map without creating an LLWString. + // Using this class as the map index instead allows us to search using segments of an existing + // text run without copying them first, which greatly reduces overhead in LLKeywords::findSegments(). + class WStringMapIndex + { + public: + // copy constructor + WStringMapIndex(const WStringMapIndex& other); + // constructor from a string (copies the string's data into the new object) + WStringMapIndex(const LLWString& str); + // constructor from pointer and length + // NOTE: does NOT copy data, caller must ensure that the lifetime of the pointer exceeds that of the new object! + WStringMapIndex(const llwchar *start, size_t length); + ~WStringMapIndex(); + bool operator<(const WStringMapIndex &other) const; + private: + void copyData(const llwchar *start, size_t length); + const llwchar *mData; + size_t mLength; + bool mOwner; + }; + + typedef std::map<WStringMapIndex, LLKeywordToken*> word_token_map_t; typedef word_token_map_t::const_iterator keyword_iterator_t; keyword_iterator_t begin() const { return mWordTokenMap.begin(); } keyword_iterator_t end() const { return mWordTokenMap.end(); } |