This is an automated email from the ASF dual-hosted git repository.
domoritz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new b754d5a4ef GH-30863: [JS] Use a singleton StructRow proxy handler
(#44289)
b754d5a4ef is described below
commit b754d5a4ef1c169771c17f88fca6558bfe6b8440
Author: Sylvain Wallez <[email protected]>
AuthorDate: Thu Oct 3 03:49:19 2024 +0200
GH-30863: [JS] Use a singleton StructRow proxy handler (#44289)
### Rationale for this change
Fixes #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: #30863
---
js/src/row/struct.ts | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/js/src/row/struct.ts b/js/src/row/struct.ts
index bc3869cb8d..074ec91fd6 100644
--- a/js/src/row/struct.ts
+++ b/js/src/row/struct.ts
@@ -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()); }
@@ -157,3 +157,5 @@ class StructRowProxyHandler<T extends TypeMap = any>
implements ProxyHandler<Str
return false;
}
}
+
+const structRowProxyHandler = new StructRowProxyHandler();