Skip to content

Comments

Fix rust binding to use the chars count instead of byte length#346

Merged
jupblb merged 1 commit intosourcegraph:mainfrom
arai-a:rust-sym-chars-count
Feb 24, 2026
Merged

Fix rust binding to use the chars count instead of byte length#346
jupblb merged 1 commit intosourcegraph:mainfrom
arai-a:rust-sym-chars-count

Conversation

@arai-a
Copy link
Contributor

@arai-a arai-a commented Nov 14, 2025

The rust binding uses self.sym.chars().nth(self.index) to access chars, but the sym.index uses the [0, self.sym.len()) range.

chars().nth() uses the char index, while sym.len() is the byte length.
This results in InvalidIndex error in SymbolParser::current if the symbol contains non-ASCII range.

This patch introduces a new field sym_len to SymbolParser, which caches the result of chars count (given it's O(N) operation),
and use it in place of sym.len().

Copy link
Member

@jupblb jupblb left a comment

Choose a reason for hiding this comment

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

Sorry for a late response!

@arai-a arai-a force-pushed the rust-sym-chars-count branch from 0e4f9d1 to ee40eb6 Compare February 24, 2026 17:02
@jupblb jupblb merged commit 3fd3fac into sourcegraph:main Feb 24, 2026
10 checks passed
@jupblb
Copy link
Member

jupblb commented Feb 24, 2026

Thanks :)

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.

2 participants