Skip to content

Commit b03fc02

Browse files
VMGen: Don't allocate the handlers table in Swift side
1 parent 1cf5998 commit b03fc02

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

Sources/WasmKit/Execution/DispatchInstruction.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,15 +1767,12 @@ extension Execution {
17671767
import _CWasmKit.InlineCode
17681768

17691769
extension Instruction {
1770-
private static let handlers: [UInt64] = withUnsafePointer(to: wasmkit_tc_exec_handlers) {
1771-
let count = MemoryLayout.size(ofValue: wasmkit_tc_exec_handlers) / MemoryLayout<wasmkit_tc_exec>.size
1772-
return $0.withMemoryRebound(to: UInt64.self, capacity: count) {
1773-
Array(UnsafeBufferPointer(start: $0, count: count))
1774-
}
1775-
}
1776-
1777-
@inline(never)
17781770
var handler: UInt64 {
1779-
return Self.handlers[Int(self.opcodeID)]
1771+
return withUnsafePointer(to: wasmkit_tc_exec_handlers) {
1772+
let count = MemoryLayout.size(ofValue: wasmkit_tc_exec_handlers) / MemoryLayout<wasmkit_tc_exec>.size
1773+
return $0.withMemoryRebound(to: UInt64.self, capacity: count) {
1774+
$0[Int(self.opcodeID)]
1775+
}
1776+
}
17801777
}
17811778
}

Utilities/Sources/VMGen.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -436,16 +436,13 @@ enum VMGen {
436436
import _CWasmKit.InlineCode
437437
438438
extension Instruction {
439-
private static let handlers: [UInt64] = withUnsafePointer(to: wasmkit_tc_exec_handlers) {
440-
let count = MemoryLayout.size(ofValue: wasmkit_tc_exec_handlers) / MemoryLayout<wasmkit_tc_exec>.size
441-
return $0.withMemoryRebound(to: UInt64.self, capacity: count) {
442-
Array(UnsafeBufferPointer(start: $0, count: count))
443-
}
444-
}
445-
446-
@inline(never)
447439
var handler: UInt64 {
448-
return Self.handlers[Int(self.opcodeID)]
440+
return withUnsafePointer(to: wasmkit_tc_exec_handlers) {
441+
let count = MemoryLayout.size(ofValue: wasmkit_tc_exec_handlers) / MemoryLayout<wasmkit_tc_exec>.size
442+
return $0.withMemoryRebound(to: UInt64.self, capacity: count) {
443+
$0[Int(self.opcodeID)]
444+
}
445+
}
449446
}
450447
}
451448

0 commit comments

Comments
 (0)