Mailinglist Archive: yast-commit (819 mails)

< Previous Next >
[yast-commit] r54432 - /trunk/core/libycp/src/YCPMap.cc
  • From: aschnell@xxxxxxxxxxxxxxxx
  • Date: Wed, 07 Jan 2009 14:07:14 -0000
  • Message-id: <E1LKZ3y-00061D-W9@xxxxxxxxxxxxxxxx>
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 <kettner@xxxxxxx>
+ Authors: Mathias Kettner <kettner@xxxxxxx>
+ Arvin Schnell <aschnell@xxxxxxx>
Maintainer: Klaus Kaempf <kkaempf@xxxxxxx>

/-*/
@@ -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@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages