mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 18:13:57 +00:00
Removes the inner loop in the endtable check written tables (#5803)
This commit is contained in:
@@ -118,7 +118,7 @@ public final class ByteBuffer {
|
|||||||
/// - size: Size of Value being written to the buffer
|
/// - size: Size of Value being written to the buffer
|
||||||
func push(struct value: UnsafeMutableRawPointer, size: Int) {
|
func push(struct value: UnsafeMutableRawPointer, size: Int) {
|
||||||
ensureSpace(size: UInt32(size))
|
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() }
|
defer { value.deallocate() }
|
||||||
_writerSize += size
|
_writerSize += size
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,19 +174,17 @@ public final class FlatBufferBuilder {
|
|||||||
|
|
||||||
var isAlreadyAdded: Int?
|
var isAlreadyAdded: Int?
|
||||||
|
|
||||||
mainLoop: for table in _vtables {
|
let vt2 = _bb.memory.advanced(by: _bb.writerIndex)
|
||||||
let vt1 = _bb.capacity - Int(table)
|
let len2 = vt2.load(fromByteOffset: 0, as: Int16.self)
|
||||||
let vt2 = _bb.writerIndex
|
|
||||||
let len = _bb.read(def: Int16.self, position: vt1)
|
for table in _vtables {
|
||||||
guard len == _bb.read(def: Int16.self, position: vt2) else { break }
|
let position = _bb.capacity - Int(table)
|
||||||
for i in stride(from: sizeofVoffset, to: Int(len), by: sizeofVoffset) {
|
let vt1 = _bb.memory.advanced(by: position)
|
||||||
let vt1ReadValue = _bb.read(def: Int16.self, position: vt1 + i)
|
let len1 = _bb.read(def: Int16.self, position: position)
|
||||||
let vt2ReadValue = _bb.read(def: Int16.self, position: vt2 + i)
|
if (len2 != len1 || 0 != memcmp(vt1, vt2, Int(len2))) { continue }
|
||||||
if vt1ReadValue != vt2ReadValue {
|
|
||||||
break mainLoop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isAlreadyAdded = Int(table)
|
isAlreadyAdded = Int(table)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if let offset = isAlreadyAdded {
|
if let offset = isAlreadyAdded {
|
||||||
|
|||||||
Reference in New Issue
Block a user