Opened 14 years ago

Closed 13 years ago

#2945 closed Feature Requests (fixed)

set, multiset, map and multimap don't take advantage of insert with hint api

Reported by: Brian Wood Owned by: Matthias Troyer
Milestone: To Be Determined Component: serialization
Version: Boost 1.38.0 Severity: Optimization
Keywords: Cc:

Description

Several of the standard containers have an insert function that can be used to improve the efficiency of adding elements to them. Here is some code that uses this function -- abt1 is a std::set<int>.

set<int>::iterator endIt1 = abt1.end();
for (unsigned int j0 = 1; j0 <= headCount[0]; ++j0) {
  // load data into an int named rep.
  abt1.insert(endIt1, rep);
}

It is possible someone may want to serialize a non-sorted list<int> to a set<int>. In this case using the hinted insert will be slightly slower than the non-hinted version. This case is somewhat rare though in my opinion.

Change History (5)

comment:1 by Robert Ramey, 14 years ago

Milestone: Boost 1.39.0To Be Determined
Status: newassigned
Type: BugsFeature Requests

I've investigated this a little bit and it looks to be a worthwhile enhancement. I'll try this out in due course.

comment:2 by Robert Ramey, 14 years ago

Of course, if this is an area you have interested and ability in, or perhaps an urgent need for, you might want to submit a tested patch. I would be pleased to consider it.

Robert Ramey

comment:3 by Robert Ramey, 13 years ago

Owner: changed from Robert Ramey to Matthias Troyer
Status: assignednew

Matias,

Seems to me that this guy is on to something here. Maybe you want to take a look at this. If you don't - re-assign this back to me.

Robert Ramey

comment:4 by anonymous, 13 years ago

I have applied this locally and it does indeed make a significant difference.

comment:5 by Robert Ramey, 13 years ago

Resolution: fixed
Status: newclosed

I'm pretty sure I added this to version 1.41. That is, I'm pretty sure it's already in there.

Robert Ramey

Note: See TracTickets for help on using tickets.