8000 Fix: remove unused parser instance by romgrk · Pull Request #22053 · atom/atom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Fix: remove unused parser instance #22053

Merged
merged 1 commit into from
May 19, 2021
Merged

Conversation

romgrk
Copy link
Contributor
@romgrk romgrk commented Mar 21, 2021

Hello, this is really trivial and also I'm not using Atom, I just happened to be reading the code, so I'll forgo the bugfix template and make it short, please close if you're not interested:

Issue

In tree-sitter-language-mode.js, each instance of the TreeSitterLanguageMode creates a new tree-sitter Parser in its constructor. This parser instance is never used because the .parse() function uses a parse instance from the PARSER_POOL array.

Solution

Don't create an unused instance.

References

this.parser = new Parser();

parse(language, oldTree, ranges) {
const parser = PARSER_POOL.pop() || new Parser();
parser.setLanguage(language);
const result = parser.parseTextBuffer(this.buffer.buffer, oldTree, {
syncTimeoutMicros: this.syncTimeoutMicros,
includedRanges: ranges
});
if (result.then) {
return result.then(tree => {
PARSER_POOL.push(parser);
return tree;
});
} else {
PARSER_POOL.push(parser);
return result;
}
}

Copy link
Contributor
@sadick254 sadick254 left a comment

Choose a reason for hiding this comment

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

Deleting code is always fun 😄 . Thank you for your contribution.

@sadick254 sadick254 merged commit 81250ab into atom:master May 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0