Skip to content

Commit

Permalink
Fix the time complexity of the MessageWriter capacity increase algo…
Browse files Browse the repository at this point in the history
…rithm.
  • Loading branch information
fumoboy007 committed Jun 19, 2024
1 parent 8809041 commit 3d7964e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/MessagePack/MessageWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public struct MessageWriter: ~Copyable {
return
}

capacity = NSRoundUpToMultipleOfPageSize(totalByteCount)
capacity = max(capacity * 2, totalByteCount)
capacity = NSRoundUpToMultipleOfPageSize(capacity)
precondition(totalByteCount <= capacity)

guard let newBaseAddress = realloc(buffer.baseAddress, capacity)?.assumingMemoryBound(to: UInt8.self) else {
Expand Down

0 comments on commit 3d7964e

Please sign in to comment.