From 370d1c43e73d4c06aabb4432b61e772ba6a66f13 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 5 Feb 2013 00:55:56 +0300 Subject: Improve a bit image particle limits checking. --- src/imageparticle.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp index c2d253641..4eab16fc9 100644 --- a/src/imageparticle.cpp +++ b/src/imageparticle.cpp @@ -23,6 +23,7 @@ #include "imageparticle.h" #include "graphics.h" +#include "logger.h" #include "resources/image.h" @@ -38,16 +39,13 @@ ImageParticle::ImageParticle(Map *const map, Image *const image): { mImage->incRef(); - std::string name = mImage->getIdPath(); - if (ImageParticle::imageParticleCountByName.find(name) - == ImageParticle::imageParticleCountByName.end()) - { + const std::string &name = mImage->getIdPath(); + std::map::iterator it + = ImageParticle::imageParticleCountByName.find(name); + if (it == ImageParticle::imageParticleCountByName.end()) ImageParticle::imageParticleCountByName[name] = 1; - } else - { - ImageParticle::imageParticleCountByName[name] ++; - } + (*it).second ++; } } @@ -55,9 +53,15 @@ ImageParticle::~ImageParticle() { if (mImage) { - std::string name = mImage->getIdPath(); - if (ImageParticle::imageParticleCountByName[name] > 0) - ImageParticle::imageParticleCountByName[name] --; + const std::string &name = mImage->getIdPath(); + std::map::iterator it + = ImageParticle::imageParticleCountByName.find(name); + if (it != ImageParticle::imageParticleCountByName.end()) + { + int &cnt = (*it).second; + if (cnt > 0) + cnt --; + } mImage->decRef(); mImage = nullptr; -- cgit v1.2.3-70-g09d2