diff options
author | Mike Antipov <mantipov@productengine.com> | 2010-02-19 11:12:38 +0200 |
---|---|---|
committer | Mike Antipov <mantipov@productengine.com> | 2010-02-19 11:12:38 +0200 |
commit | 3fb3b9cf217dce42991b288f5caf0266932bef94 (patch) | |
tree | e5a0bb8b7deb4602ab45d8a49793658aeaed3677 /indra/llui/llkeywords.h | |
parent | c4a3bee33562f607bbd56a420bfcb424e00f2f41 (diff) | |
parent | e1c8cd395e8238958a5d2cfdaadaca4046e00811 (diff) |
Merge from default branch
--HG--
branch : product-engine
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(); } |