Skip to content

Commit

Permalink
apacheGH-30863: [JS] Use a singleton StructRow proxy handler (apache#…
Browse files Browse the repository at this point in the history
…44289)

### Rationale for this change

Fixes apache#30863 by using a singleton proxy handler in `StructRow`'s
constructor. Since the handler is stateless, there is no need to create
a new instance for each row.

### What changes are included in this PR?

Refactoring `StructRow`'s constructor to extract the proxy handler.

### Are these changes tested?

No additional tests since this is an internal refactoring, but `yarn
test` runs successfully.

### Are there any user-facing changes?

No.

* GitHub Issue: apache#30863
  • Loading branch information
swallez authored Oct 3, 2024
1 parent b8eae60 commit b754d5a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion js/src/row/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class StructRow<T extends TypeMap = any> {
constructor(parent: Data<Struct<T>>, rowIndex: number) {
this[kParent] = parent;
this[kRowIndex] = rowIndex;
return new Proxy(this, new StructRowProxyHandler());
return new Proxy(this, structRowProxyHandler);
}

public toArray() { return Object.values(this.toJSON()); }
Expand Down Expand Up @@ -157,3 +157,5 @@ class StructRowProxyHandler<T extends TypeMap = any> implements ProxyHandler<Str
return false;
}
}

const structRowProxyHandler = new StructRowProxyHandler();

0 comments on commit b754d5a

Please sign in to comment.