Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions Sources/FoundationEssentials/Data/Data+Base64.swift
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,21 @@ extension Base64 {
let other = pointer?.bindMemory(to: UInt8.self, capacity: outputLength)
let target = UnsafeMutableBufferPointer(start: other, count: outputLength)
var length = outputLength
if options.contains(.ignoreUnknownCharacters) {
try Self._decodeIgnoringErrors(from: inBuffer, into: target, length: &length, options: options)
} else {
// for whatever reason I can see this being 10% faster for larger payloads. Maybe better
// branch prediction?
try self._decode(from: inBuffer, into: target, length: &length, options: options)
do {
if options.contains(.ignoreUnknownCharacters) {
try Self._decodeIgnoringErrors(from: inBuffer, into: target, length: &length, options: options)
} else {
// for whatever reason I can see this being 10% faster for larger payloads. Maybe better
// branch prediction?
try self._decode(from: inBuffer, into: target, length: &length, options: options)
}

return Data(bytesNoCopy: pointer!, count: length, deallocator: .free)
} catch {
// Do not leak the malloc on error
free(pointer)
throw error
}

return Data(bytesNoCopy: pointer!, count: length, deallocator: .free)
}

static func _decode(
Expand Down