From e37156a305532819533eeeb05be96a6935edf849 Mon Sep 17 00:00:00 2001 From: Joakim Hassila Date: Sat, 16 Apr 2022 11:25:44 +0200 Subject: [PATCH] Keep the underlying storage capacity when clearing the FlatBufferBuilder. Gives a significant performance boost for serialisation of many small messages. (#7250) --- swift/Sources/FlatBuffers/FlatBufferBuilder.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swift/Sources/FlatBuffers/FlatBufferBuilder.swift b/swift/Sources/FlatBuffers/FlatBufferBuilder.swift index 5ccc7e44c..223f7ffa9 100644 --- a/swift/Sources/FlatBuffers/FlatBufferBuilder.swift +++ b/swift/Sources/FlatBuffers/FlatBufferBuilder.swift @@ -127,8 +127,8 @@ public struct FlatBufferBuilder { mutating public func clear() { _minAlignment = 0 isNested = false - stringOffsetMap = [:] - _vtables = [] + stringOffsetMap.removeAll(keepingCapacity: true) + _vtables.removeAll(keepingCapacity: true) _vtableStorage.clear() _bb.clear() }