diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-04-19 23:02:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-19 23:02:07 +0200 |
commit | f3fe62a0bf9e775b3e6e838f104ab605a2238792 (patch) | |
tree | 1335fc9752d54924dd3a8f22e70d555fb54945c8 /src/inventory.cpp | |
parent | cfe0291b131630a7400fdcf46b720bd70d8d0fa0 (diff) | |
download | minetest-f3fe62a0bf9e775b3e6e838f104ab605a2238792.tar.gz minetest-f3fe62a0bf9e775b3e6e838f104ab605a2238792.tar.bz2 minetest-f3fe62a0bf9e775b3e6e838f104ab605a2238792.zip |
Fix various copy instead of const ref reported by cppcheck (#5615)
* Also remove InventoryList::peekItem unused function
* Fix some post increment to preincrement reported by cppcheck
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index 6d5b49916..8617f7263 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -46,12 +46,11 @@ static content_t content_translate_from_19_to_internal(content_t c_from) } ItemStack::ItemStack(const std::string &name_, u16 count_, - u16 wear_, IItemDefManager *itemdef) + u16 wear_, IItemDefManager *itemdef) : + name(itemdef->getAlias(name_)), + count(count_), + wear(wear_) { - name = itemdef->getAlias(name_); - count = count_; - wear = wear_; - if (name.empty() || count == 0) clear(); else if (itemdef->get(name).type == ITEM_TOOL) @@ -370,14 +369,13 @@ ItemStack ItemStack::peekItem(u32 peekcount) const Inventory */ -InventoryList::InventoryList(std::string name, u32 size, IItemDefManager *itemdef) +InventoryList::InventoryList(const std::string &name, u32 size, IItemDefManager *itemdef): + m_name(name), + m_size(size), + m_width(0), + m_itemdef(itemdef) { - m_name = name; - m_size = size; - m_width = 0; - m_itemdef = itemdef; clearItems(); - //m_dirty = false; } InventoryList::~InventoryList() @@ -712,14 +710,6 @@ ItemStack InventoryList::takeItem(u32 i, u32 takecount) return taken; } -ItemStack InventoryList::peekItem(u32 i, u32 peekcount) const -{ - if(i >= m_items.size()) - return ItemStack(); - - return m_items[i].peekItem(peekcount); -} - void InventoryList::moveItemSomewhere(u32 i, InventoryList *dest, u32 count) { // Take item from source list |