Skip to content

Use lazy initializations for decorators and type parameters in parser #554

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

Merged
merged 7 commits into from
Mar 22, 2019
Merged

Use lazy initializations for decorators and type parameters in parser #554

merged 7 commits into from
Mar 22, 2019

Conversation

MaxGraey
Copy link
Member

No description provided.

@MaxGraey MaxGraey requested a review from dcodeIO March 21, 2019 20:20
@MaxGraey MaxGraey changed the title Use lazy initializations for decorators and parameters in parser Use lazy initializations for decorators and type parameters in parser Mar 21, 2019
@@ -939,7 +939,8 @@ export class Parser extends DiagnosticEmitter {

// at '<': TypeParameter (',' TypeParameter)* '>'

var typeParameters = new Array<TypeParameterNode>();
// var typeParameters = new Array<TypeParameterNode>();
var typeParameters: TypeParameterNode[] | null = null;
Copy link
Member

Choose a reason for hiding this comment

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

Now I'm wondering: If we are already at <, the usual case here is that we'll end up with an array and not null since <> is invalid. If we had the Array.create<TypeParameterNode>(1) helper I mentioned in the runtime PR (the one that would guarantee a backing buffer for at least one element but with length=0), that might make the most sense here as it avoids the (most of the time) redundant null check below. Wdyt?

Copy link
Member Author

@MaxGraey MaxGraey Mar 21, 2019

Choose a reason for hiding this comment

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

I think it could be even better. Reserve not 1 element but for example 8 when array is created. And this elements btw could store outside of buffer exactly inside Array class. Similar approach have SmallVector in binaryen and LLVM's SmallVector

@dcodeIO dcodeIO merged commit f9a8d2f into AssemblyScript:master Mar 22, 2019
@MaxGraey MaxGraey deleted the some-improvments branch March 22, 2019 11:20
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