mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 11:57:32 +09:00
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
This commit is contained in:
parent
252a22d066
commit
442f6b3252
2 changed files with 20 additions and 38 deletions
|
|
@ -381,10 +381,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
|
||||
|
|
|
|||
|
|
@ -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) \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue