Skip to content

Commit b721d43

Browse files
Quick optimization for local types parsing
The locals representation is apparently not optimal, so we should use better data structures later. For now we can apply a quick fix to be enough fast for large number of locals.
1 parent 18408ab commit b721d43

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/WasmParser/WasmParser.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,13 +1018,13 @@ extension Parser {
10181018
throw WasmParserError.tooManyLocals
10191019
}
10201020

1021-
let locals = localTypes.map { (n: UInt32, type: ValueType) in
1022-
return (0..<n).map { _ in type }
1021+
let locals = localTypes.flatMap { (n: UInt32, type: ValueType) in
1022+
return Array(repeating: type, count: Int(n))
10231023
}
10241024
let expressionBytes = try stream.consume(
10251025
count: Int(size) - (stream.currentIndex - bodyStart)
10261026
)
1027-
return Code(locals: locals.flatMap { $0 }, expression: expressionBytes)
1027+
return Code(locals: locals, expression: expressionBytes)
10281028
}
10291029
}
10301030

0 commit comments

Comments
 (0)