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

SourceFile sets up _lineStarts eagerly #36

Open
klavs opened this issue Jul 20, 2019 · 0 comments
Open

SourceFile sets up _lineStarts eagerly #36

klavs opened this issue Jul 20, 2019 · 0 comments
Labels
contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) type-enhancement A request for a change that isn't a bug

Comments

@klavs
Copy link

klavs commented Jul 20, 2019

The body of the SourceFile.decoded could be executed lazily. It would increase the performance for cases when serialisation of spans is not necessary. For example, doing successful AST transformations without needing to report errors.

SourceFile.decoded(Iterable<int> decodedChars, {url})
: url = url is String ? Uri.parse(url) : url,
_decodedChars = new Uint32List.fromList(decodedChars.toList()) {
for (var i = 0; i < _decodedChars.length; i++) {
var c = _decodedChars[i];
if (c == _CR) {
// Return not followed by newline is treated as a newline
var j = i + 1;
if (j >= _decodedChars.length || _decodedChars[j] != _LF) c = _LF;
}
if (c == _LF) _lineStarts.add(i + 1);
}
}

@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) labels Nov 7, 2019
nex3 pushed a commit to nex3/source_span that referenced this issue Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants