Skip to content

Commit 635bb62

Browse files
committed
[stdlib] tweaks to MutableRawSpan
1 parent 810d7a2 commit 635bb62

File tree

1 file changed

+19
-40
lines changed

1 file changed

+19
-40
lines changed

stdlib/public/core/Span/MutableRawSpan.swift

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ extension MutableRawSpan {
308308
}
309309

310310
@_alwaysEmitIntoClient
311-
public func storeBytes<T: BitwiseCopyable>(
311+
public mutating func storeBytes<T: BitwiseCopyable>(
312312
of value: T, toByteOffset offset: Int = 0, as type: T.Type
313313
) {
314314
_precondition(
@@ -321,7 +321,7 @@ extension MutableRawSpan {
321321

322322
@unsafe
323323
@_alwaysEmitIntoClient
324-
public func storeBytes<T: BitwiseCopyable>(
324+
public mutating func storeBytes<T: BitwiseCopyable>(
325325
of value: T, toUncheckedByteOffset offset: Int, as type: T.Type
326326
) {
327327
unsafe _start().storeBytes(of: value, toByteOffset: offset, as: type)
@@ -334,20 +334,18 @@ extension MutableRawSpan {
334334

335335
@_alwaysEmitIntoClient
336336
public mutating func update<S: Sequence>(
337-
startingAt byteOffset: Int = 0,
338337
from source: S
339338
) -> (unwritten: S.Iterator, byteOffset: Int) where S.Element: BitwiseCopyable {
340339
var iterator = source.makeIterator()
341-
let offset = update(startingAt: byteOffset, from: &iterator)
340+
let offset = update(from: &iterator)
342341
return (iterator, offset)
343342
}
344343

345344
@_alwaysEmitIntoClient
346345
public mutating func update<Element: BitwiseCopyable>(
347-
startingAt byteOffset: Int = 0,
348346
from elements: inout some IteratorProtocol<Element>
349347
) -> Int {
350-
var offset = byteOffset
348+
var offset = 0
351349
while offset + MemoryLayout<Element>.stride <= _count {
352350
guard let element = elements.next() else { break }
353351
unsafe storeBytes(
@@ -360,18 +358,15 @@ extension MutableRawSpan {
360358

361359
@_alwaysEmitIntoClient
362360
public mutating func update<C: Collection>(
363-
startingAt byteOffset: Int = 0,
364361
fromContentsOf source: C
365362
) -> Int where C.Element: BitwiseCopyable {
366363
let newOffset = source.withContiguousStorageIfAvailable {
367-
self.update(
368-
startingAt: byteOffset, fromContentsOf: Span(_unsafeElements: $0)
369-
)
364+
self.update(fromContentsOf: RawSpan(_unsafeElements: $0))
370365
}
371366
if let newOffset { return newOffset }
372367

373368
var elements = source.makeIterator()
374-
let lastOffset = update(startingAt: byteOffset, from: &elements)
369+
let lastOffset = update(from: &elements)
375370
_precondition(
376371
elements.next() == nil,
377372
"destination span cannot contain every element from source."
@@ -381,45 +376,40 @@ extension MutableRawSpan {
381376

382377
@_alwaysEmitIntoClient
383378
public mutating func update<Element: BitwiseCopyable>(
384-
startingAt byteOffset: Int = 0,
385379
fromContentsOf source: Span<Element>
386380
) -> Int {
387-
// update(startingAt: byteOffset, from: source.bytes)
381+
// update(from: source.bytes)
388382
source.withUnsafeBytes {
389-
update(startingAt: byteOffset, fromContentsOf: $0)
383+
update(fromContentsOf: $0)
390384
}
391385
}
392386

393387
@_alwaysEmitIntoClient
394388
public mutating func update<Element: BitwiseCopyable>(
395-
startingAt byteOffset: Int = 0,
396389
fromContentsOf source: borrowing MutableSpan<Element>
397390
) -> Int {
398-
// update(startingAt: byteOffset, from: source.storage.bytes)
391+
// update(from: source.span.bytes)
399392
source.withUnsafeBytes {
400-
update(startingAt: byteOffset, fromContentsOf: $0)
393+
update(fromContentsOf: $0)
401394
}
402395
}
403396

404397
@_alwaysEmitIntoClient
405398
public mutating func update(
406-
startingAt byteOffset: Int = 0,
407-
from source: RawSpan
399+
fromContentsOf source: RawSpan
408400
) -> Int {
409-
if source.byteCount == 0 { return byteOffset }
401+
if source.byteCount == 0 { return 0 }
410402
source.withUnsafeBytes {
411-
unsafe _start().advanced(by: byteOffset)
412-
.copyMemory(from: $0.baseAddress!, byteCount: $0.count)
403+
unsafe _start().copyMemory(from: $0.baseAddress!, byteCount: $0.count)
413404
}
414-
return byteOffset &+ source.byteCount
405+
return source.byteCount
415406
}
416407

417408
@_alwaysEmitIntoClient
418409
public mutating func update(
419-
startingAt byteOffset: Int = 0,
420-
from source: borrowing MutableRawSpan
410+
fromContentsOf source: borrowing MutableRawSpan
421411
) -> Int {
422-
update(startingAt: byteOffset, from: source.bytes)
412+
update(fromContentsOf: source.bytes)
423413
}
424414
}
425415

@@ -514,20 +504,9 @@ extension MutableRawSpan {
514504
@unsafe
515505
@_alwaysEmitIntoClient
516506
@lifetime(borrow self)
517-
mutating public func _extracting(
518-
unchecked bounds: some RangeExpression<Int>
519-
) -> Self {
520-
unsafe _extracting(unchecked: bounds.relative(to: byteOffsets))
521-
}
522-
523-
@unsafe
524-
@_alwaysEmitIntoClient
525-
@lifetime(borrow self)
526-
mutating public func _extracting(
527-
unchecked bounds: ClosedRange<Int>
528-
) -> Self {
529-
let range = Range(
530-
_uncheckedBounds: (bounds.lowerBound, bounds.upperBound&+1)
507+
mutating public func _extracting(unchecked bounds: ClosedRange<Int>) -> Self {
508+
let range = unsafe Range(
509+
uncheckedBounds: (bounds.lowerBound, bounds.upperBound+1)
531510
)
532511
return unsafe _extracting(unchecked: range)
533512
}

0 commit comments

Comments
 (0)