wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src image.cpp


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src image.cpp
Date: Tue, 08 Feb 2005 16:12:22 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    05/02/08 21:12:22

Modified files:
        src            : image.cpp 

Log message:
        Fix image existence with zipios, and sanitize/optimize the code.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/image.cpp.diff?tr1=1.74&tr2=1.75&r1=text&r2=text

Patches:
Index: wesnoth/src/image.cpp
diff -u wesnoth/src/image.cpp:1.74 wesnoth/src/image.cpp:1.75
--- wesnoth/src/image.cpp:1.74  Tue Feb  8 20:31:55 2005
+++ wesnoth/src/image.cpp       Tue Feb  8 21:12:22 2005
@@ -622,26 +622,18 @@
 
 bool exists(const image::locator& i_locator)
 {
-       bool ret=false;
-
-       if(i_locator.get_type() != image::locator::FILE && 
-                       i_locator.get_type() != image::locator::SUB_FILE) 
+       typedef image::locator loc;
+       loc::type type = i_locator.get_type();
+       if (type != loc::FILE && type != loc::SUB_FILE) 
                return false;
 
-       if(image_existance_map.find(i_locator) != image_existance_map.end())
-               return image_existance_map[i_locator];
-
-#ifdef USE_ZIPIOS
-       if(file_exists("images/" + i_locator.get_filename()))
-               ret = true;
-#else
-       if(get_binary_file_location("images",i_locator.get_filename()).empty() 
== false) {
-               ret = true;
-       }
-#endif
-       image_existance_map[i_locator] = ret;
-
-       return ret;
+       // the insertion will fail if there is already an element in the cache
+       std::pair< std::map< image::locator, bool >::iterator, bool >
+               it = image_existance_map.insert(std::make_pair(i_locator, 
false));
+       bool &cache = it.first->second;
+       if (it.second)
+               cache = !get_binary_file_location("images", 
i_locator.get_filename()).empty();
+       return cache;
 }
 
 surface getMinimap(int w, int h, const gamemap& map, const team* tm)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]