@@ -341,15 +341,14 @@ extension Base64 {
341
341
return self . encodeToData ( bytes: Array ( bytes) , options: options)
342
342
}
343
343
344
- @usableFromInline
345
344
static func _encode( input: UnsafeBufferPointer < UInt8 > , buffer: UnsafeMutableBufferPointer < UInt8 > , length: inout Int , options: Data . Base64EncodingOptions ) {
346
345
if options. contains ( . lineLength64Characters) || options. contains ( . lineLength76Characters) {
347
346
return self . _encodeWithLineBreaks ( input: input, buffer: buffer, length: & length, options: options)
348
347
}
349
348
350
349
let omitPaddingCharacter = false // options.contains(.omitPaddingCharacter)
351
350
352
- Self . withUnsafeEncodingTablesAsBufferPointers ( options: options) { e0, e1 in
351
+ Self . withUnsafeEncodingTablesAsBufferPointers ( options: options) { ( e0, e1) throws ( Never ) -> Void in
353
352
let to = input. count / 3 * 3
354
353
var outIndex = 0
355
354
for index in stride ( from: 0 , to: to, by: 3 ) {
@@ -372,18 +371,19 @@ extension Base64 {
372
371
373
372
buffer [ outIndex] = e0 [ Int ( i1) ]
374
373
375
- if let i2 = i2, let i3 = i3 {
376
- buffer [ outIndex &+ 1 ] = e1 [ Int ( ( ( i1 & 0x03 ) &<< 4 ) | ( ( i2 &>> 4 ) & 0x0F ) ) ]
377
- buffer [ outIndex &+ 2 ] = e1 [ Int ( ( ( i2 & 0x0F ) &<< 2 ) | ( ( i3 &>> 6 ) & 0x03 ) ) ]
378
- buffer [ outIndex &+ 3 ] = e1 [ Int ( i3) ]
379
- outIndex += 4
380
- } else if let i2 = i2 {
374
+ if let i2 = i2 {
381
375
buffer [ outIndex &+ 1 ] = e1 [ Int ( ( ( i1 & 0x03 ) &<< 4 ) | ( ( i2 &>> 4 ) & 0x0F ) ) ]
382
- buffer [ outIndex &+ 2 ] = e1 [ Int ( ( i2 & 0x0F ) &<< 2 ) ]
383
- outIndex += 3
384
- if !omitPaddingCharacter {
385
- buffer [ outIndex] = Self . encodePaddingCharacter
386
- outIndex &+= 1
376
+ if let i3 = i3 {
377
+ buffer [ outIndex &+ 2 ] = e1 [ Int ( ( ( i2 & 0x0F ) &<< 2 ) | ( ( i3 &>> 6 ) & 0x03 ) ) ]
378
+ buffer [ outIndex &+ 3 ] = e1 [ Int ( i3) ]
379
+ outIndex += 4
380
+ } else {
381
+ buffer [ outIndex &+ 2 ] = e1 [ Int ( ( i2 & 0x0F ) &<< 2 ) ]
382
+ outIndex += 3
383
+ if !omitPaddingCharacter {
384
+ buffer [ outIndex] = Self . encodePaddingCharacter
385
+ outIndex &+= 1
386
+ }
387
387
}
388
388
} else {
389
389
buffer [ outIndex &+ 1 ] = e1 [ Int ( ( i1 & 0x03 ) << 4 ) ]
@@ -522,15 +522,15 @@ extension Base64 {
522
522
return capacityWithoutBreaks + lineBreakCapacity
523
523
}
524
524
525
- static func withUnsafeEncodingTablesAsBufferPointers< R> ( options: Data . Base64EncodingOptions , _ body: ( UnsafeBufferPointer < UInt8 > , UnsafeBufferPointer < UInt8 > ) throws -> R ) rethrows -> R {
525
+ static func withUnsafeEncodingTablesAsBufferPointers< R, E : Error > ( options: Data . Base64EncodingOptions , _ body: ( UnsafeBufferPointer < UInt8 > , UnsafeBufferPointer < UInt8 > ) throws ( E ) -> R ) throws ( E ) -> R {
526
526
let encoding0 = Self . encoding0
527
527
let encoding1 = Self . encoding1
528
528
529
529
assert ( encoding0. count == 256 )
530
530
assert ( encoding1. count == 256 )
531
531
532
- return try encoding0. withUnsafeBufferPointer { e0 -> R in
533
- try encoding1. withUnsafeBufferPointer { e1 -> R in
532
+ return try encoding0. withUnsafeBufferPointer { e0 throws ( E ) -> R in
533
+ try encoding1. withUnsafeBufferPointer { e1 throws ( E ) -> R in
534
534
try body ( e0, e1)
535
535
}
536
536
}
0 commit comments