Author: aschnell
Date: Wed Jan 7 15:07:14 2009
New Revision: 54432
URL: http://svn.opensuse.org/viewcvs/yast?rev=54432&view=rev
Log:
- give map.insert a position hint
Modified:
trunk/core/libycp/src/YCPMap.cc
Modified: trunk/core/libycp/src/YCPMap.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/src/YCPMap.cc?rev=54432&r1=54431&r2=54432&view=diff
==============================================================================
--- trunk/core/libycp/src/YCPMap.cc (original)
+++ trunk/core/libycp/src/YCPMap.cc Wed Jan 7 15:07:14 2009
@@ -12,7 +12,8 @@
File: YCPMap.cc
- Author: Mathias Kettner
+ Authors: Mathias Kettner
+ Arvin Schnell
Maintainer: Klaus Kaempf
/-*/
@@ -56,12 +57,20 @@
ycp2error ("Only integer, string, or symbol constant allowed as key in map");
return;
}
- YCPValueYCPValueMap::iterator pos = stl_map.find( key );
- if ( pos == stl_map.end() )
- stl_map.insert( YCPValueYCPValueMap::value_type( key, value ) );
+ // note: 'stl_map[key] = value' would create a temporary object using the
+ // default constructor for YCPValue.
+
+ YCPMap::iterator pos = stl_map.lower_bound(key);
+ if (pos == stl_map.end() || !pos->first->equal(key))
+ {
+ // pos is just a hint but can avoid a second search through the map
+ stl_map.insert(pos, YCPMap::value_type(key, value));
+ }
else
+ {
pos->second = value;
+ }
}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org