Closed
Bug 580633
Opened 16 years ago
Closed 16 years ago
Do less copying when adding elements to HashMap
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
People
(Reporter: luke, Assigned: luke)
Details
(Whiteboard: fixed-in-tracemonkey)
Attachments
(1 file)
|
3.31 KB,
patch
|
bzbarsky
:
review+
|
Details | Diff | Splinter Review |
Although it boils away for builtin types, if you are storing a key or value with a non-trivial operator=/copy-constructor, HashMap will copy more than it needs to when inserting elements. The solution is to make HashTable's interface a bit more fragile, which is fine since its an implementation detail of HashMap/HashSet, and let the caller do the assignment directly.
Attachment #459012 -
Flags: review?(bzbarsky)
Comment 1•16 years ago
|
||
Comment on attachment 459012 [details] [diff] [review]
fix
Looks fine, but for HashMap (not HashSet, where the operation makes no sense), would it make sense to also add this function:
bool add(AddPtr &p, const Key &k) {
Entry *pentry;
if (!impl.add(p, &pentry))
return false;
const_cast<Key &>(pentry->key) = k;
return true;
}
(relying on pentry->value being default-constructed already)? Or would that not work for some reason?
Attachment #459012 -
Flags: review?(bzbarsky) → review+
| Assignee | ||
Comment 2•16 years ago
|
||
That would totally work
Comment 3•16 years ago
|
||
Let's do that, then. Then we get no-copy inserts as needed!
| Assignee | ||
Comment 4•16 years ago
|
||
| Assignee | ||
Updated•16 years ago
|
Whiteboard: fixed-in-tracemonkey
Comment 5•16 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•