зеркало из https://github.com/mozilla/pjs.git
Bug 740153 - Don't expose Entry directly through HashMap; r=luke
HashMap and HashSet only expose Entries through Ptr and Range, except for one variant of put. They also don't expose the default size they use if you call init() without an argument. These weirdnesses seem to be interface carried over from the old jsdhash. The first oddness is unused and can be removed, the second should simply get exposed to make it easier to wrap HashMap and HashSet. --HG-- extra : rebase_source : e1432a9af189229f379158ba0529956ddbf5f234
This commit is contained in:
Родитель
874e95e27f
Коммит
7b5b7e4b4a
|
@ -985,12 +985,14 @@ class HashMap
|
|||
Impl impl;
|
||||
|
||||
public:
|
||||
const static unsigned sDefaultInitSize = Impl::sDefaultInitSize;
|
||||
|
||||
/*
|
||||
* HashMap construction is fallible (due to OOM); thus the user must call
|
||||
* init after constructing a HashMap and check the return value.
|
||||
*/
|
||||
HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {}
|
||||
bool init(uint32_t len = Impl::sDefaultInitSize) { return impl.init(len); }
|
||||
HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {}
|
||||
bool init(uint32_t len = sDefaultInitSize) { return impl.init(len); }
|
||||
bool initialized() const { return impl.initialized(); }
|
||||
|
||||
/*
|
||||
|
@ -1153,13 +1155,13 @@ class HashMap
|
|||
|
||||
/* Overwrite existing value with v. Return NULL on oom. */
|
||||
template<typename KeyInput, typename ValueInput>
|
||||
Entry *put(const KeyInput &k, const ValueInput &v) {
|
||||
bool put(const KeyInput &k, const ValueInput &v) {
|
||||
AddPtr p = lookupForAdd(k);
|
||||
if (p) {
|
||||
p->value = v;
|
||||
return &*p;
|
||||
return true;
|
||||
}
|
||||
return add(p, k, v) ? &*p : NULL;
|
||||
return add(p, k, v);
|
||||
}
|
||||
|
||||
/* Like put, but assert that the given key is not already present. */
|
||||
|
@ -1223,12 +1225,14 @@ class HashSet
|
|||
Impl impl;
|
||||
|
||||
public:
|
||||
const static unsigned sDefaultInitSize = Impl::sDefaultInitSize;
|
||||
|
||||
/*
|
||||
* HashSet construction is fallible (due to OOM); thus the user must call
|
||||
* init after constructing a HashSet and check the return value.
|
||||
*/
|
||||
HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {}
|
||||
bool init(uint32_t len = Impl::sDefaultInitSize) { return impl.init(len); }
|
||||
HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {}
|
||||
bool init(uint32_t len = sDefaultInitSize) { return impl.init(len); }
|
||||
bool initialized() const { return impl.initialized(); }
|
||||
|
||||
/*
|
||||
|
@ -1362,10 +1366,10 @@ class HashSet
|
|||
return impl.lookup(l) != NULL;
|
||||
}
|
||||
|
||||
/* Overwrite existing value with v. Return NULL on oom. */
|
||||
const T *put(const T &t) {
|
||||
/* Overwrite existing value with v. Return false on oom. */
|
||||
bool put(const T &t) {
|
||||
AddPtr p = lookupForAdd(t);
|
||||
return p ? &*p : (add(p, t) ? &*p : NULL);
|
||||
return p ? true : add(p, t);
|
||||
}
|
||||
|
||||
/* Like put, but assert that the given key is not already present. */
|
||||
|
|
Загрузка…
Ссылка в новой задаче