Skip to content

Commit 234016c

Browse files
committed
Bug 1477626 - Document some differences between mozilla::HashTable and PLDHashTable. r=Waldo
MozReview-Commit-ID: DB0KUy99DDM --HG-- extra : rebase_source : 4d14c47c48cb821f6c69654c1c5d90c48f217e48
1 parent f3ea3c7 commit 234016c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

mfbt/HashTable.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66

7+
// A note on the differences between mozilla::HashTable and PLDHashTable (and
8+
// its subclasses, such as nsTHashtable).
9+
//
10+
// - mozilla::HashTable is a lot faster, largely because it uses templates
11+
// throughout *and* inlines everything. PLDHashTable inlines operations much
12+
// less aggressively, and also uses "virtual ops" for operations like hashing
13+
// and matching entries that require function calls.
14+
//
15+
// - Correspondingly, mozilla::HashTable use is likely to increase executable
16+
// size much more than PLDHashTable.
17+
//
18+
// - mozilla::HashTable has a nicer API, with a proper HashSet vs. HashMap
19+
// distinction.
20+
//
21+
// - mozilla::HashTable requires more explicit OOM checking. Use
22+
// mozilla::InfallibleAllocPolicy to make allocations infallible; note that
23+
// return values of possibly-allocating methods such as add() will still need
24+
// checking in some fashion -- e.g. with MOZ_ALWAYS_TRUE() -- due to the use
25+
// of MOZ_MUST_USE.
26+
//
27+
// - mozilla::HashTable has a default capacity on creation of 32 and a minimum
28+
// capacity of 4. PLDHashTable has a default capacity on creation of 8 and a
29+
// minimum capacity of 8.
30+
//
31+
// - mozilla::HashTable allocates memory eagerly. PLDHashTable delays
32+
// allocating until the first element is inserted.
33+
734
#ifndef mozilla_HashTable_h
835
#define mozilla_HashTable_h
936

xpcom/ds/PLDHashTable.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66

7+
// See the comment at the top of mfbt/HashTable.h for a comparison between
8+
// PLDHashTable and mozilla::HashTable.
9+
710
#ifndef PLDHashTable_h
811
#define PLDHashTable_h
912

xpcom/ds/nsTHashtable.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66

7+
// See the comment at the top of mfbt/HashTable.h for a comparison between
8+
// PLDHashTable and mozilla::HashTable.
9+
710
#ifndef nsTHashtable_h__
811
#define nsTHashtable_h__
912

0 commit comments

Comments
 (0)