diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-11-30 15:42:59 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-11-30 15:42:59 +0100 |
commit | b4b589a11875ed290d8b632c7a69b89b293f864c (patch) | |
tree | 8f950a7ed4a02074d62ac2c1621c213f03f809cc /memory | |
parent | a954e19ea2f65cc4f7798027ef4658c5cbcb3290 (diff) | |
download | UXP-b4b589a11875ed290d8b632c7a69b89b293f864c.tar UXP-b4b589a11875ed290d8b632c7a69b89b293f864c.tar.gz UXP-b4b589a11875ed290d8b632c7a69b89b293f864c.tar.lz UXP-b4b589a11875ed290d8b632c7a69b89b293f864c.tar.xz UXP-b4b589a11875ed290d8b632c7a69b89b293f864c.zip |
Issue #1307 - Part 4: Stop using variable-length arrays.
"USING VLA'S IS ACTIVELY STUPID! It generates much more code, and much
slower code (and more fragile code), than just using a fixed key size
would have done." -- Linus Torvalds
Diffstat (limited to 'memory')
-rw-r--r-- | memory/mozjemalloc/jemalloc.c | 4 | ||||
-rw-r--r-- | memory/mozjemalloc/rb.h | 54 |
2 files changed, 20 insertions, 38 deletions
diff --git a/memory/mozjemalloc/jemalloc.c b/memory/mozjemalloc/jemalloc.c index ccbc1aeba..c46e3c047 100644 --- a/memory/mozjemalloc/jemalloc.c +++ b/memory/mozjemalloc/jemalloc.c @@ -378,10 +378,6 @@ void *_mmap(void *addr, size_t length, int prot, int flags, #define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) #endif -#ifdef MOZ_MEMORY_WINDOWS - /* MSVC++ does not support C99 variable-length arrays. */ -# define RB_NO_C99_VARARRAYS -#endif #include "rb.h" #ifdef MALLOC_DEBUG diff --git a/memory/mozjemalloc/rb.h b/memory/mozjemalloc/rb.h index 431ad9ddb..a1b08973b 100644 --- a/memory/mozjemalloc/rb.h +++ b/memory/mozjemalloc/rb.h @@ -36,7 +36,6 @@ * (Optional.) * #define SIZEOF_PTR ... * #define SIZEOF_PTR_2POW ... - * #define RB_NO_C99_VARARRAYS * * (Optional, see assert(3).) * #define NDEBUG @@ -769,39 +768,26 @@ a_prefix##remove(a_tree_type *tree, a_type *node) { \ * effort. */ -#ifdef RB_NO_C99_VARARRAYS - /* - * Avoid using variable-length arrays, at the cost of using more stack space. - * Size the path arrays such that they are always large enough, even if a - * tree consumes all of memory. Since each node must contain a minimum of - * two pointers, there can never be more nodes than: - * - * 1 << ((SIZEOF_PTR<<3) - (SIZEOF_PTR_2POW+1)) - * - * Since the depth of a tree is limited to 3*lg(#nodes), the maximum depth - * is: - * - * (3 * ((SIZEOF_PTR<<3) - (SIZEOF_PTR_2POW+1))) - * - * This works out to a maximum depth of 87 and 180 for 32- and 64-bit - * systems, respectively (approximatly 348 and 1440 bytes, respectively). - */ -# define rbp_compute_f_height(a_type, a_field, a_tree) -# define rbp_f_height (3 * ((SIZEOF_PTR<<3) - (SIZEOF_PTR_2POW+1))) -# define rbp_compute_fr_height(a_type, a_field, a_tree) -# define rbp_fr_height (3 * ((SIZEOF_PTR<<3) - (SIZEOF_PTR_2POW+1))) -#else -# define rbp_compute_f_height(a_type, a_field, a_tree) \ - /* Compute the maximum possible tree depth (3X the black height). */\ - unsigned rbp_f_height; \ - rbp_black_height(a_type, a_field, a_tree, rbp_f_height); \ - rbp_f_height *= 3; -# define rbp_compute_fr_height(a_type, a_field, a_tree) \ - /* Compute the maximum possible tree depth (3X the black height). */\ - unsigned rbp_fr_height; \ - rbp_black_height(a_type, a_field, a_tree, rbp_fr_height); \ - rbp_fr_height *= 3; -#endif +/* + * Avoid using variable-length arrays. + * Size the path arrays such that they are always large enough, even if a + * tree consumes all of memory. Since each node must contain a minimum of + * two pointers, there can never be more nodes than: + * + * 1 << ((SIZEOF_PTR<<3) - (SIZEOF_PTR_2POW+1)) + * + * Since the depth of a tree is limited to 3*lg(#nodes), the maximum depth + * is: + * + * (3 * ((SIZEOF_PTR<<3) - (SIZEOF_PTR_2POW+1))) + * + * This works out to a maximum depth of 87 and 180 for 32- and 64-bit + * systems, respectively (approximatly 348 and 1440 bytes, respectively). + */ +#define rbp_compute_f_height(a_type, a_field, a_tree) +#define rbp_f_height (3 * ((SIZEOF_PTR<<3) - (SIZEOF_PTR_2POW+1))) +#define rbp_compute_fr_height(a_type, a_field, a_tree) +#define rbp_fr_height (3 * ((SIZEOF_PTR<<3) - (SIZEOF_PTR_2POW+1))) #define rb_foreach_begin(a_type, a_field, a_tree, a_var) { \ rbp_compute_f_height(a_type, a_field, a_tree) \ |