Closed Bug 583729 Opened 14 years ago Closed 7 months ago

js hashtable - ability to reserve

Categories

(Core :: JavaScript Engine, enhancement)

Other Branch
enhancement

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: igor, Unassigned)

Details

It would be nice to add to HashTable and HashSet a method similar to Vector::reserve that would guarantee that the following additions to the table would always succeed. The current init method allows to do that only during initialization which is insufficient.
One problem is that if reserve simply makes the table bigger, and the user does a remove before reaching the reserved size, then checkUnderloaded would shrink the table back down.
(In reply to comment #1)
> One problem is that if reserve simply makes the table bigger, and the user does
> a remove before reaching the reserved size, then checkUnderloaded would shrink
> the table back down.

This is fine as my use case is to avoid writing the release operation in code like:

key = prepare_key();
if (!key)
    return false;
if (!hashtable.put(key, value)) {
    release_key(key);
    return false;
}

With reserve that would be 

if (!hashtable.reserve(length() + 1))
    return false;
key = prepare_key();
if (!key)
    return false;
hashtable.put(key, value);
Assignee: general → nobody
Severity: normal → S3
Status: NEW → RESOLVED
Closed: 7 months ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.