GeezerVison is showing github.com — Reduce byteLength calls for JSTypedArray · swiftwasm/JavaScriptKit@31ae862
File tree
Expand file treeCollapse file tree
Open diff view settings
Sources/JavaScriptKit/BasicObjects
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -82,7 +82,7 @@ public class JSTypedArray<Element>: JSBridgedClass, ExpressibleByArrayLiteral wh |
82 | 82 | let rawBuffer = malloc(bytesLength)! |
83 | 83 | defer { free(rawBuffer) } |
84 | 84 | _load_typed_array(jsObject.id, rawBuffer.assumingMemoryBound(to: UInt8.self)) |
85 | | - let length = lengthInBytes / MemoryLayout<Element>.size |
| 85 | + let length = bytesLength / MemoryLayout<Element>.size |
86 | 86 | let boundPtr = rawBuffer.bindMemory(to: Element.self, capacity: length) |
87 | 87 | let bufferPtr = UnsafeBufferPointer<Element>(start: boundPtr, count: length) |
88 | 88 | let result = try body(bufferPtr) |
@@ -109,7 +109,7 @@ public class JSTypedArray<Element>: JSBridgedClass, ExpressibleByArrayLiteral wh |
109 | 109 | let rawBuffer = malloc(bytesLength)! |
110 | 110 | defer { free(rawBuffer) } |
111 | 111 | _load_typed_array(jsObject.id, rawBuffer.assumingMemoryBound(to: UInt8.self)) |
112 | | - let length = lengthInBytes / MemoryLayout<Element>.size |
| 112 | + let length = bytesLength / MemoryLayout<Element>.size |
113 | 113 | let boundPtr = rawBuffer.bindMemory(to: Element.self, capacity: length) |
114 | 114 | let bufferPtr = UnsafeBufferPointer<Element>(start: boundPtr, count: length) |
115 | 115 | let result = try await body(bufferPtr) |
|