Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type of idx parameter in Child() and NamedChild() methods. #50

Open
m-kru opened this issue Oct 6, 2021 · 3 comments
Open

Type of idx parameter in Child() and NamedChild() methods. #50

m-kru opened this issue Oct 6, 2021 · 3 comments

Comments

@m-kru
Copy link

m-kru commented Oct 6, 2021

Child() and NamedChiled() parameters are currently int. Shouldn't they be of type uint32?

// Child returns the node's child at the given index, where zero represents the first child.
func (n Node) Child(idx int) *Node {
	nn := C.ts_node_child(n.c, C.uint32_t(idx))
	return n.t.cachedNode(nn)
}

// NamedChild returns the node's *named* child at the given index.
func (n Node) NamedChild(idx int) *Node {
	nn := C.ts_node_named_child(n.c, C.uint32_t(idx))
	return n.t.cachedNode(nn)
}
@m-kru
Copy link
Author

m-kru commented Jun 14, 2022

@smacker ping

@smacker
Copy link
Owner

smacker commented Jun 14, 2022

hi @m-kru ! Is there any particular reason you need it to be unit32?

Int type is at least 32 bytes.

I chose to use int instead of unit32 here because it is the most common integer type in Go according to my experience and is normally used for indexing. Build-in functions such as len or copy also operate with int type which allows to avoid type conversion.

@m-kru
Copy link
Author

m-kru commented Jun 15, 2022

Well, the only reason is that they are never negative. However, I also understand your point on len and copy.

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

No branches or pull requests

2 participants