summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-02-05 00:55:56 +0300
committerAndrei Karas <akaras@inbox.ru>2013-02-05 00:55:56 +0300
commit370d1c43e73d4c06aabb4432b61e772ba6a66f13 (patch)
treea85b7c30d8b7c29428d36d1c24b5c26a3057b15b /src
parentb671f16dd633944ed3ea01dd8b50c0d51f77b081 (diff)
downloadplus-370d1c43e73d4c06aabb4432b61e772ba6a66f13.tar.gz
plus-370d1c43e73d4c06aabb4432b61e772ba6a66f13.tar.bz2
plus-370d1c43e73d4c06aabb4432b61e772ba6a66f13.tar.xz
plus-370d1c43e73d4c06aabb4432b61e772ba6a66f13.zip
Improve a bit image particle limits checking.
Diffstat (limited to 'src')
-rw-r--r--src/imageparticle.cpp26
1 files changed, 15 insertions, 11 deletions
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<std::string, int>::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<std::string, int>::iterator it
+ = ImageParticle::imageParticleCountByName.find(name);
+ if (it != ImageParticle::imageParticleCountByName.end())
+ {
+ int &cnt = (*it).second;
+ if (cnt > 0)
+ cnt --;
+ }
mImage->decRef();
mImage = nullptr;