summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%google.com <devnull@localhost>2008-01-19 06:04:29 +0000
committerwtc%google.com <devnull@localhost>2008-01-19 06:04:29 +0000
commit0f322fd3cc279140d05621f8b4a256cad6673d13 (patch)
treeed7800f330d4834e67f421fe0a0e533ef12a1aa7
parent7d4eaf9dbfdf36bfda93c92366061fae3739f826 (diff)
downloadnspr-hg-0f322fd3cc279140d05621f8b4a256cad6673d13.tar.gz
Bug 404824: use a look-up table to avoid expensive PR_CeilingLog2
calculations for common cases. The patch is contributed by Steve Snyder <swsnyder@insightbb.com>. r=nelson,wtc
-rw-r--r--lib/ds/plarena.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/ds/plarena.c b/lib/ds/plarena.c
index 638f5bdb..dc3af0b4 100644
--- a/lib/ds/plarena.c
+++ b/lib/ds/plarena.c
@@ -111,9 +111,23 @@ PR_IMPLEMENT(void) PL_InitArenaPool(
#pragma unused (name)
#endif
+ /*
+ * Look-up table of PR_BITMASK(PR_CeilingLog2(align)) values for
+ * align = 1 to 32.
+ */
+ static const PRUint8 pmasks[33] = {
+ 0, /* not used */
+ 0, 1, 3, 3, 7, 7, 7, 7,15,15,15,15,15,15,15,15, /* 1 ... 16 */
+ 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31}; /* 17 ... 32 */
+
if (align == 0)
align = PL_ARENA_DEFAULT_ALIGN;
- pool->mask = PR_BITMASK(PR_CeilingLog2(align));
+
+ if (align < sizeof(pmasks)/sizeof(pmasks[0]))
+ pool->mask = pmasks[align];
+ else
+ pool->mask = PR_BITMASK(PR_CeilingLog2(align));
+
pool->first.next = NULL;
pool->first.base = pool->first.avail = pool->first.limit =
(PRUword)PL_ARENA_ALIGN(pool, &pool->first + 1);