mirror of
https://gitlab.isc.org/isc-projects/bind9.git
synced 2025-12-05 18:57:04 -06:00
shrunk cfgobj down from 48 bytes to 40 bytes
Follow-up of 38ce2906 as the size of the `cfg_obj_t` can actually goes
down to 40 bytes "for free", by using bitfields to only use 31 bits for
the `line` field, so the remaining bit can be use to hold the `cloned`
state without paying the extra 8 bytes padding.
This commit is contained in:
@@ -206,9 +206,20 @@ struct cfg_obj {
|
||||
* These two 4 byte fields are contiguous to avoid an extra
|
||||
* padding of 4 bytes each, avoiding an extra 8 bytes in the
|
||||
* struct.
|
||||
*
|
||||
* `line` is 31 bits long (~2,000,000,000 is likely enough lines in a
|
||||
* named config) so the `cloned` boolean fit in the extra bit, and won't
|
||||
* take extra 8 bits because of padding.
|
||||
*/
|
||||
unsigned int magic;
|
||||
unsigned int line;
|
||||
unsigned int line : 31;
|
||||
|
||||
/*%
|
||||
* Indicates that an object was cloned from the defaults
|
||||
* or otherwise generated during the configuration merge
|
||||
* process.
|
||||
*/
|
||||
bool cloned : 1;
|
||||
|
||||
isc_refcount_t references;
|
||||
cfg_obj_t *file; /*%< separate string with its own refcount */
|
||||
@@ -226,13 +237,6 @@ struct cfg_obj {
|
||||
cfg_netprefix_t *netprefix;
|
||||
isccfg_duration_t *duration;
|
||||
} value;
|
||||
|
||||
/*%
|
||||
* Indicates that an object was cloned from the defaults
|
||||
* or otherwise generated during the configuration merge
|
||||
* process.
|
||||
*/
|
||||
bool cloned;
|
||||
};
|
||||
|
||||
/*% A list element. */
|
||||
|
||||
@@ -73,8 +73,8 @@
|
||||
* can take a significant amount of memory. This assert ensures that we
|
||||
* won't increase its size by mistake without getting a warning.
|
||||
*/
|
||||
static_assert(sizeof(struct cfg_obj) <= 48,
|
||||
"sizeof(cfg_obj_t) must be 48 bytes");
|
||||
static_assert(sizeof(struct cfg_obj) <= 40,
|
||||
"sizeof(cfg_obj_t) must be 40 bytes");
|
||||
|
||||
/* Shorthand */
|
||||
#define CAT CFG_LOGCATEGORY_CONFIG
|
||||
|
||||
Reference in New Issue
Block a user