Skip to content

Use pull-style iterators to build index and tree#55

Merged
bwesterb merged 2 commits intomainfrom
issue-49
Apr 22, 2025
Merged

Use pull-style iterators to build index and tree#55
bwesterb merged 2 commits intomainfrom
issue-49

Conversation

@bwesterb
Copy link
Owner

Closes #49

@bwesterb bwesterb changed the title Use pull-style iterators to buld index and tree Use pull-style iterators to build index and tree Apr 22, 2025
// T is a pointer type, so by default nil. We need to allocate t
// first. The obvious t = new(T) is wrong, as new(T) is of type *T
// instead of T. The following does what we want.
reflect.ValueOf(&t).Elem().Set(reflect.New(reflect.TypeOf(t).Elem()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we end up doing this multiple times (here and in unmarshalOne below), might be worth moving to a separate function:

func allocate[T any]() T {
	var t T
	reflect.ValueOf(&t).Elem().Set(reflect.New(reflect.TypeOf(t).Elem()))
	return t
}

Then can have just t := allocate[T]() in the functions.

Copy link
Owner Author

@bwesterb bwesterb Apr 22, 2025

Choose a reason for hiding this comment

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

Thought about it, but we first need to check if it changes allocation/inlining behaviour. Also repeating something twice isn't that bad.

bwesterb added a commit that referenced this pull request Apr 22, 2025
Co-authored-by: Luke Valenta <lvalenta@cloudflare.com>
Co-authored-by: Luke Valenta <lvalenta@cloudflare.com>
@bwesterb bwesterb merged commit 7609062 into main Apr 22, 2025
1 check passed
@bwesterb bwesterb deleted the issue-49 branch April 22, 2025 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move from push-style iterators to cursors and builders

2 participants