summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/stash.cc
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-04-26 14:19:36 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-04-26 14:19:36 +0000
commit269a1da76046334717fed84754ca3bde5f5bffc5 (patch)
treef18d2735d22f93615926b38886a5e625954b7920 /crawl-ref/source/stash.cc
parentc392dcf1c56371e09a9775b0df04aaa1ad4d2f3e (diff)
downloadcrawl-ref-269a1da76046334717fed84754ca3bde5f5bffc5.tar.gz
crawl-ref-269a1da76046334717fed84754ca3bde5f5bffc5.zip
Minor speedup in stash item name generation: use const_cast<> instead of
copying a temporary. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1373 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/stash.cc')
-rw-r--r--crawl-ref/source/stash.cc39
1 files changed, 25 insertions, 14 deletions
diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc
index c8f7806990..92b400cc33 100644
--- a/crawl-ref/source/stash.cc
+++ b/crawl-ref/source/stash.cc
@@ -647,30 +647,33 @@ std::string ShopInfo::shop_item_name(const shop_item &si) const
{
char shopitem[ITEMNAME_SIZE * 2];
- // mangle a temporary
- item_def temp_item = si.item;
+ const unsigned long oldflags = si.item.flags;
+
if ( shoptype_identifies_stock(this->shoptype) )
- temp_item.flags |= ISFLAG_IDENT_MASK;
+ const_cast<shop_item&>(si).item.flags |= ISFLAG_IDENT_MASK;
- const std::string itemname = Stash::stash_item_name(temp_item);
+ const std::string itemname = Stash::stash_item_name(si.item);
snprintf(shopitem, sizeof shopitem, "%s (%u gold)",
itemname.c_str(), si.price);
+ if ( oldflags != si.item.flags )
+ const_cast<shop_item&>(si).item.flags = oldflags;
+
return shopitem;
}
std::string ShopInfo::shop_item_desc(const shop_item &si) const
{
std::string desc;
+
+ const unsigned long oldflags = si.item.flags;
- // mangle a temporary
- item_def temp_item = si.item;
if (shoptype_identifies_stock(this->shoptype))
- temp_item.flags |= ISFLAG_IDENT_MASK;
+ const_cast<shop_item&>(si).item.flags |= ISFLAG_IDENT_MASK;
- if (is_dumpable_artifact(temp_item, Options.verbose_dump))
+ if (is_dumpable_artifact(si.item, Options.verbose_dump))
{
- desc = munge_description(get_item_description(temp_item,
+ desc = munge_description(get_item_description(si.item,
Options.verbose_dump,
true));
trim_string(desc);
@@ -680,16 +683,24 @@ std::string ShopInfo::shop_item_desc(const shop_item &si) const
if (desc[i] == '\n')
desc.insert(i + 1, " ");
}
+
+ if ( oldflags != si.item.flags )
+ const_cast<shop_item&>(si).item.flags = oldflags;
+
return desc;
}
void ShopInfo::describe_shop_item(const shop_item &si) const
{
- // mangle a temporary
- item_def temp_item = si.item;
- if ( shoptype_identifies_stock(this->shoptype) )
- temp_item.flags |= ISFLAG_IDENT_MASK;
- describe_item( temp_item );
+ const unsigned long oldflags = si.item.flags;
+
+ if (shoptype_identifies_stock(this->shoptype))
+ const_cast<shop_item&>(si).item.flags |= ISFLAG_IDENT_MASK;
+
+ describe_item( si.item );
+
+ if ( oldflags != si.item.flags )
+ const_cast<shop_item&>(si).item.flags = oldflags;
}
bool ShopInfo::show_menu(const std::string &place,