X Tutup
Skip to content

Remove raw base pointer from GDScript#111490

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
HolonProduction:rm-base
Nov 7, 2025
Merged

Remove raw base pointer from GDScript#111490
Repiteo merged 1 commit intogodotengine:masterfrom
HolonProduction:rm-base

Conversation

@HolonProduction
Copy link
Member

Currently GDScript stores its base once as Ref<GDScript> (base) and once as raw GDScript* (_base). They are always set/unset together, the raw pointer is just assigned base->ptr(). So the value of those should always be the same.

The comment on _base reads as if the raw pointer was cached for performance. However Ref::ptr is at the moment force inlined and just returns the raw pointer that the ref uses. So based on my knowledge it should be equally as fast. Both members are present since 0b806ee so maybe ref did have some overhead at some point.

Main advantage is preventing invalid states and to remove noise from the code.

Copy link
Member

@dalexeev dalexeev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Note that _FORCE_INLINE_ does not generally guarantee inlining: for dev and size-optimized builds, the inline keyword is used instead of an attribute, so the compiler will determine whether to inline based on its own heuristics. However, the compiler will likely always inline ptr(), since it is a trivial accessor.

godot/core/typedefs.h

Lines 76 to 84 in cb3af5a

// Should always inline, except in dev builds because it makes debugging harder,
// or `size_enabled` builds where inlining is actively avoided.
#ifndef _FORCE_INLINE_
#if defined(DEV_ENABLED) || defined(SIZE_EXTRA)
#define _FORCE_INLINE_ inline
#else
#define _FORCE_INLINE_ _ALWAYS_INLINE_
#endif
#endif

_FORCE_INLINE_ T *ptr() const {
return reference;
}

Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

@Repiteo Repiteo merged commit fae64fb into godotengine:master Nov 7, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 7, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup