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

Use concat (+=) rather than join #3311

Closed
lpatiny opened this issue Dec 9, 2024 · 1 comment · Fixed by #3312
Closed

Use concat (+=) rather than join #3311

lpatiny opened this issue Dec 9, 2024 · 1 comment · Fixed by #3312
Assignees

Comments

@lpatiny
Copy link
Member

lpatiny commented Dec 9, 2024

export class PathBuilder {
private array: string[] = [];
public moveTo(x: number, y: number) {
x = clamp(x);
y = clamp(y);
this.array.push(`M ${x} ${y}`);
}
public lineTo(x: number, y: number) {
x = clamp(x);
y = clamp(y);
this.array.push(`L ${x} ${y}`);
}
public closePath() {
if (this.array.length > 0) this.array.push('Z');
}
public toString() {
return this.array.join(' ');
}
public concatPath(pathBuilder: PathBuilder) {
return this.array.concat(pathBuilder.array).join(' ');
}
}

Today making += is faster than join

Image

@hamed-musallam
Copy link
Member

Indeed, string concatenation appears to perform better than using join

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

2 participants