diff options
author | mustiikhalil <mustii@mmk.one> | 2020-03-12 22:13:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-12 12:13:03 -0700 |
commit | 0dba63909fb2959994fec11c704c5d5ea45e8d83 (patch) | |
tree | 23d9370a2cc2cc2e81a3f4492795d440a03c1070 /swift/Sources | |
parent | 0e3fdd0eeac998974179fd48874a2d98dbf9af83 (diff) | |
download | flatbuffers-0dba63909fb2959994fec11c704c5d5ea45e8d83.tar.gz flatbuffers-0dba63909fb2959994fec11c704c5d5ea45e8d83.tar.bz2 flatbuffers-0dba63909fb2959994fec11c704c5d5ea45e8d83.zip |
Removes the inner loop in the endtable check written tables (#5803)
Diffstat (limited to 'swift/Sources')
-rw-r--r-- | swift/Sources/FlatBuffers/ByteBuffer.swift | 2 | ||||
-rw-r--r-- | swift/Sources/FlatBuffers/FlatBufferBuilder.swift | 22 |
2 files changed, 11 insertions, 13 deletions
diff --git a/swift/Sources/FlatBuffers/ByteBuffer.swift b/swift/Sources/FlatBuffers/ByteBuffer.swift index 0c523178..e468227c 100644 --- a/swift/Sources/FlatBuffers/ByteBuffer.swift +++ b/swift/Sources/FlatBuffers/ByteBuffer.swift @@ -118,7 +118,7 @@ public final class ByteBuffer { /// - size: Size of Value being written to the buffer func push(struct value: UnsafeMutableRawPointer, size: Int) { ensureSpace(size: UInt32(size)) - _memory.advanced(by: writerIndex - size).copyMemory(from: value, byteCount: size) + memcpy(_memory.advanced(by: writerIndex - size), value, size) defer { value.deallocate() } _writerSize += size } diff --git a/swift/Sources/FlatBuffers/FlatBufferBuilder.swift b/swift/Sources/FlatBuffers/FlatBufferBuilder.swift index cf479fd6..8afa7596 100644 --- a/swift/Sources/FlatBuffers/FlatBufferBuilder.swift +++ b/swift/Sources/FlatBuffers/FlatBufferBuilder.swift @@ -174,19 +174,17 @@ public final class FlatBufferBuilder { var isAlreadyAdded: Int? - mainLoop: for table in _vtables { - let vt1 = _bb.capacity - Int(table) - let vt2 = _bb.writerIndex - let len = _bb.read(def: Int16.self, position: vt1) - guard len == _bb.read(def: Int16.self, position: vt2) else { break } - for i in stride(from: sizeofVoffset, to: Int(len), by: sizeofVoffset) { - let vt1ReadValue = _bb.read(def: Int16.self, position: vt1 + i) - let vt2ReadValue = _bb.read(def: Int16.self, position: vt2 + i) - if vt1ReadValue != vt2ReadValue { - break mainLoop - } - } + let vt2 = _bb.memory.advanced(by: _bb.writerIndex) + let len2 = vt2.load(fromByteOffset: 0, as: Int16.self) + + for table in _vtables { + let position = _bb.capacity - Int(table) + let vt1 = _bb.memory.advanced(by: position) + let len1 = _bb.read(def: Int16.self, position: position) + if (len2 != len1 || 0 != memcmp(vt1, vt2, Int(len2))) { continue } + isAlreadyAdded = Int(table) + break } if let offset = isAlreadyAdded { |