summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/showsymb.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2012-10-16 23:48:21 +0200
committerAdam Borowski <kilobyte@angband.pl>2012-10-16 23:59:14 +0200
commit06c43eb0b206f629c289836fd719d444db9607a8 (patch)
tree9fb89d35eeacb2e42c3f27068613a78bd66c8f1c /crawl-ref/source/showsymb.cc
parent5eec67434e2cfa8fc198758ce3a9c3fde20b4f1b (diff)
downloadcrawl-ref-06c43eb0b206f629c289836fd719d444db9607a8.tar.gz
crawl-ref-06c43eb0b206f629c289836fd719d444db9607a8.zip
Reduce repeating item_glyph regexp matches by caching results per name.
This still requires costly production of the item's name, once per every item visible on screen every single round.
Diffstat (limited to 'crawl-ref/source/showsymb.cc')
-rw-r--r--crawl-ref/source/showsymb.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/crawl-ref/source/showsymb.cc b/crawl-ref/source/showsymb.cc
index 004035ea09..80544488ec 100644
--- a/crawl-ref/source/showsymb.cc
+++ b/crawl-ref/source/showsymb.cc
@@ -212,6 +212,13 @@ static cglyph_t _get_item_override(const item_def &item)
string name = stash_annotate_item(STASH_LUA_SEARCH_ANNOTATE, &item)
+ item.name(DESC_PLAIN);
+ {
+ // Check the cache...
+ map<string, cglyph_t>::const_iterator ir = Options.item_glyph_cache.find(name);
+ if (ir != Options.item_glyph_cache.end())
+ return ir->second;
+ }
+
for (map<string, cglyph_t>::const_iterator ir = Options.item_glyph_overrides.begin();
ir != Options.item_glyph_overrides.end(); ++ir)
{
@@ -228,6 +235,12 @@ static cglyph_t _get_item_override(const item_def &item)
}
}
+ // Matching against a list of regexps can be costly, save up to 1000
+ // last matches.
+ if (Options.item_glyph_cache.size() >= 1000)
+ Options.item_glyph_cache.clear();
+ Options.item_glyph_cache[name] = g;
+
return g;
}