Rename internal fields and variables in AHashMap, HashMap and HashSet#107045
Merged
Repiteo merged 1 commit intogodotengine:masterfrom Sep 18, 2025
Merged
Rename internal fields and variables in AHashMap, HashMap and HashSet#107045Repiteo merged 1 commit intogodotengine:masterfrom
AHashMap, HashMap and HashSet#107045Repiteo merged 1 commit intogodotengine:masterfrom
Conversation
eb472bd to
7cd8c6b
Compare
lawnjelly
approved these changes
Jul 1, 2025
Member
lawnjelly
left a comment
There was a problem hiding this comment.
This looks like straight forward renaming, and the reasoning seems sound in the OP.
Caveat I'm not super familiar with these hash maps (it's been a while since I looked at any of them).
Contributor
|
Needs a rebase to account for #108836 |
…shSet` for consistency.
7cd8c6b to
46b88dc
Compare
Contributor
|
Thanks! |
Contributor
|
This broke all the debug visualizers. godot.natvis, the gdb scripts, etc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AHashMap,HashMapandHashSethave inconsistent field and variable names - not only between themselves, but also internally, and across the codebase.When I personally tried to understand the code, this threw me off many times, and made the classes extremely hard to understand and compare.
I've renamed variables to be consistent. This should help these classes be more maintainable.
Change List
HashMapData name:
AHashMapuses (globally declared)HashMapDatato storehashandelement_idx. However, the name makes it sounds like it stores data.Solution: I've renamed the field to
AHashMap::Metadata. This is consistent with naming terminology of hash maps in other libraries.AHashMap::Metadatais a struct of a union of a struct oruint64_t: This is very confusing.Solution: I've changed
Metadatato be astruct, and whenever both elements are assigned at once, aMetadatainstance is used, instead of assigning.dataunion. I tested performance (get,get missing,insert,insert existing,erase), and found no regressions (if anything, it's 1-2% faster now).Indexes are inconsistently named: Indexes are named
pos,index,idx,kpos,hpos, among others. Further, inAHashMapandHashSet,posmay refer to either key or hash index inconsistently, even within the same function. This makes it extremely difficult to know at a glance which kind of index you're looking at.Solution:
HashMaphas only one kind of index. All indices are calledidx.AHashMaphas elements and metadata, so it now usesmetadata_idxandelement_idx.HashSethas hashes and keys, so it now useshash_idxandkey_idx.capacity_idxis now consistently namedcapacity_idx.Fields are indistinguishable from local variables: For example,
AHashMaphas localcapacityand the fieldcapacity.Solution: Private fields are prefixed with underscore
_to mark them as such.capacity is indistinguishable from capacity mask:
AHashMaphas fieldcapacity, but it's actuallycapacity - 1.Solution: I've renamed the field to
_capacity_mask.num_elements is inconsistent with
sizeof other containers: Other collections likeArrayusesize()to refer to the number of elements in the collection. The public APIs of hash maps also usesize(), but the internal field is callednum_elements.Solution:
num_elementsis renamed tosizefor consistency.There are other, smaller changes to pull everything together, but I think this covers the big ones.