mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-05 04:47:04 +00:00
Improves the performance of the string imp (#8772)
Improves the performance of the implementation in Swift by using withCString instead of the contigiousString
This commit is contained in:
@@ -207,7 +207,9 @@ public struct FlatBufferBuilder {
|
||||
len: size &+ (prefix ? size : 0) &+ FileIdLength,
|
||||
alignment: _minAlignment)
|
||||
assert(fileId.count == FileIdLength, "Flatbuffers requires file id to be 4")
|
||||
_bb.push(string: fileId, len: 4)
|
||||
fileId.withCString { ptr in
|
||||
_bb.writeBytes(ptr, len: 4)
|
||||
}
|
||||
finish(offset: offset, addPrefix: prefix)
|
||||
}
|
||||
|
||||
@@ -706,8 +708,9 @@ public struct FlatBufferBuilder {
|
||||
let len = str.utf8.count
|
||||
notNested()
|
||||
preAlign(len: len &+ 1, type: UOffset.self)
|
||||
_bb.fill(padding: 1)
|
||||
_bb.push(string: str, len: len)
|
||||
str.withCString { ptr in
|
||||
_bb.writeBytes(ptr, len: len &+ 1)
|
||||
}
|
||||
push(element: UOffset(len))
|
||||
return Offset(offset: _bb.size)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user