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

fix: Remove for-of syntax from values helpers for JSC memory reduction #33

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nasty-cobras-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphql.web': patch
---

Remove `for-of` syntax from `valueFromTypeNode` and `valueFromASTUntyped` helpers for JSC memory reduction.
10 changes: 7 additions & 3 deletions src/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ export function valueFromASTUntyped(
return node.value;
case 'ListValue': {
const values: unknown[] = [];
for (const value of node.values) values.push(valueFromASTUntyped(value, variables));
for (let i = 0, l = node.values.length; i < l; i++)
values.push(valueFromASTUntyped(node.values[i], variables));
return values;
}
case 'ObjectValue': {
const obj = Object.create(null);
for (const field of node.fields)
for (let i = 0, l = node.fields.length; i < l; i++) {
const field = node.fields[i];
obj[field.name.value] = valueFromASTUntyped(field.value, variables);
}
return obj;
}
case 'Variable':
Expand All @@ -47,7 +50,8 @@ export function valueFromTypeNode(
} else if (type.kind === 'ListType') {
if (node.kind === 'ListValue') {
const values: unknown[] = [];
for (const value of node.values) {
for (let i = 0, l = node.values.length; i < l; i++) {
const value = node.values[i];
const coerced = valueFromTypeNode(value, type.type, variables);
if (coerced === undefined) {
return undefined;
Expand Down
Loading