Skip to content

Commit 3e893c2

Browse files
committed
[stdlib] de-underscore the extracting() methods
1 parent f742a75 commit 3e893c2

File tree

4 files changed

+69
-69
lines changed

4 files changed

+69
-69
lines changed

stdlib/public/core/Span/MutableRawSpan.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,13 @@ extension MutableRawSpan {
439439
/// - Complexity: O(1)
440440
@_alwaysEmitIntoClient
441441
@lifetime(borrow self)
442-
mutating public func _extracting(_ bounds: Range<Int>) -> Self {
442+
mutating public func extracting(_ bounds: Range<Int>) -> Self {
443443
_precondition(
444444
UInt(bitPattern: bounds.lowerBound) <= UInt(bitPattern: _count) &&
445445
UInt(bitPattern: bounds.upperBound) <= UInt(bitPattern: _count),
446446
"Index range out of bounds"
447447
)
448-
return unsafe _extracting(unchecked: bounds)
448+
return unsafe extracting(unchecked: bounds)
449449
}
450450

451451
/// Constructs a new span over the items within the supplied range of
@@ -466,7 +466,7 @@ extension MutableRawSpan {
466466
@unsafe
467467
@_alwaysEmitIntoClient
468468
@lifetime(borrow self)
469-
mutating public func _extracting(unchecked bounds: Range<Int>) -> Self {
469+
mutating public func extracting(unchecked bounds: Range<Int>) -> Self {
470470
let newStart = unsafe _pointer?.advanced(by: bounds.lowerBound)
471471
let newSpan = unsafe Self(_unchecked: newStart, byteCount: bounds.count)
472472
return unsafe _overrideLifetime(newSpan, mutating: &self)
@@ -487,10 +487,10 @@ extension MutableRawSpan {
487487
/// - Complexity: O(1)
488488
@_alwaysEmitIntoClient
489489
@lifetime(borrow self)
490-
mutating public func _extracting(
490+
mutating public func extracting(
491491
_ bounds: some RangeExpression<Int>
492492
) -> Self {
493-
_extracting(bounds.relative(to: byteOffsets))
493+
extracting(bounds.relative(to: byteOffsets))
494494
}
495495

496496
/// Constructs a new span over the items within the supplied range of
@@ -511,11 +511,11 @@ extension MutableRawSpan {
511511
@unsafe
512512
@_alwaysEmitIntoClient
513513
@lifetime(borrow self)
514-
mutating public func _extracting(unchecked bounds: ClosedRange<Int>) -> Self {
514+
mutating public func extracting(unchecked bounds: ClosedRange<Int>) -> Self {
515515
let range = unsafe Range(
516516
_uncheckedBounds: (bounds.lowerBound, bounds.upperBound+1)
517517
)
518-
return unsafe _extracting(unchecked: range)
518+
return unsafe extracting(unchecked: range)
519519
}
520520

521521
/// Constructs a new span over all the items of this span.
@@ -529,7 +529,7 @@ extension MutableRawSpan {
529529
/// - Complexity: O(1)
530530
@_alwaysEmitIntoClient
531531
@lifetime(borrow self)
532-
mutating public func _extracting(_: UnboundedRange) -> Self {
532+
mutating public func extracting(_: UnboundedRange) -> Self {
533533
let newSpan = unsafe Self(_unchecked: _start(), byteCount: _count)
534534
return unsafe _overrideLifetime(newSpan, mutating: &self)
535535
}
@@ -556,7 +556,7 @@ extension MutableRawSpan {
556556
/// - Complexity: O(1)
557557
@_alwaysEmitIntoClient
558558
@lifetime(borrow self)
559-
mutating public func _extracting(first maxLength: Int) -> Self {
559+
mutating public func extracting(first maxLength: Int) -> Self {
560560
_precondition(maxLength >= 0, "Can't have a prefix of negative length")
561561
let newCount = min(maxLength, byteCount)
562562
let newSpan = unsafe Self(_unchecked: _pointer, byteCount: newCount)
@@ -579,7 +579,7 @@ extension MutableRawSpan {
579579
/// - Complexity: O(1)
580580
@_alwaysEmitIntoClient
581581
@lifetime(borrow self)
582-
mutating public func _extracting(droppingLast k: Int) -> Self {
582+
mutating public func extracting(droppingLast k: Int) -> Self {
583583
_precondition(k >= 0, "Can't drop a negative number of elements")
584584
let droppedCount = min(k, byteCount)
585585
let newCount = byteCount &- droppedCount
@@ -604,7 +604,7 @@ extension MutableRawSpan {
604604
/// - Complexity: O(1)
605605
@_alwaysEmitIntoClient
606606
@lifetime(borrow self)
607-
mutating public func _extracting(last maxLength: Int) -> Self {
607+
mutating public func extracting(last maxLength: Int) -> Self {
608608
_precondition(maxLength >= 0, "Can't have a suffix of negative length")
609609
let newCount = min(maxLength, byteCount)
610610
let newStart = unsafe _pointer?.advanced(by: byteCount &- newCount)
@@ -628,7 +628,7 @@ extension MutableRawSpan {
628628
/// - Complexity: O(1)
629629
@_alwaysEmitIntoClient
630630
@lifetime(borrow self)
631-
mutating public func _extracting(droppingFirst k: Int) -> Self {
631+
mutating public func extracting(droppingFirst k: Int) -> Self {
632632
_precondition(k >= 0, "Can't drop a negative number of bytes")
633633
let droppedCount = min(k, byteCount)
634634
let newStart = unsafe _pointer?.advanced(by: droppedCount)

stdlib/public/core/Span/MutableSpan.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,13 @@ extension MutableSpan where Element: ~Copyable {
645645
/// - Complexity: O(1)
646646
@_alwaysEmitIntoClient
647647
@lifetime(borrow self)
648-
mutating public func _extracting(_ bounds: Range<Index>) -> Self {
648+
mutating public func extracting(_ bounds: Range<Index>) -> Self {
649649
_precondition(
650650
UInt(bitPattern: bounds.lowerBound) <= UInt(bitPattern: _count) &&
651651
UInt(bitPattern: bounds.upperBound) <= UInt(bitPattern: _count),
652652
"Index range out of bounds"
653653
)
654-
return unsafe _extracting(unchecked: bounds)
654+
return unsafe extracting(unchecked: bounds)
655655
}
656656

657657
/// Constructs a new span over the items within the supplied range of
@@ -672,7 +672,7 @@ extension MutableSpan where Element: ~Copyable {
672672
@unsafe
673673
@_alwaysEmitIntoClient
674674
@lifetime(borrow self)
675-
mutating public func _extracting(unchecked bounds: Range<Index>) -> Self {
675+
mutating public func extracting(unchecked bounds: Range<Index>) -> Self {
676676
let delta = bounds.lowerBound &* MemoryLayout<Element>.stride
677677
let newStart = unsafe _pointer?.advanced(by: delta)
678678
let newSpan = unsafe Self(_unchecked: newStart, count: bounds.count)
@@ -694,10 +694,10 @@ extension MutableSpan where Element: ~Copyable {
694694
/// - Complexity: O(1)
695695
@_alwaysEmitIntoClient
696696
@lifetime(borrow self)
697-
mutating public func _extracting(
697+
mutating public func extracting(
698698
_ bounds: some RangeExpression<Index>
699699
) -> Self {
700-
_extracting(bounds.relative(to: indices))
700+
extracting(bounds.relative(to: indices))
701701
}
702702

703703
/// Constructs a new span over the items within the supplied range of
@@ -718,13 +718,13 @@ extension MutableSpan where Element: ~Copyable {
718718
@unsafe
719719
@_alwaysEmitIntoClient
720720
@lifetime(borrow self)
721-
mutating public func _extracting(
721+
mutating public func extracting(
722722
unchecked bounds: ClosedRange<Index>
723723
) -> Self {
724724
let range = unsafe Range(
725725
_uncheckedBounds: (bounds.lowerBound, bounds.upperBound&+1)
726726
)
727-
return unsafe _extracting(unchecked: range)
727+
return unsafe extracting(unchecked: range)
728728
}
729729

730730
/// Constructs a new span over all the items of this span.
@@ -738,7 +738,7 @@ extension MutableSpan where Element: ~Copyable {
738738
/// - Complexity: O(1)
739739
@_alwaysEmitIntoClient
740740
@lifetime(borrow self)
741-
mutating public func _extracting(_: UnboundedRange) -> Self {
741+
mutating public func extracting(_: UnboundedRange) -> Self {
742742
let newSpan = unsafe Self(_unchecked: _start(), count: _count)
743743
return unsafe _overrideLifetime(newSpan, mutating: &self)
744744
}
@@ -765,7 +765,7 @@ extension MutableSpan where Element: ~Copyable {
765765
/// - Complexity: O(1)
766766
@_alwaysEmitIntoClient
767767
@lifetime(borrow self)
768-
mutating public func _extracting(first maxLength: Int) -> Self {
768+
mutating public func extracting(first maxLength: Int) -> Self {
769769
_precondition(maxLength >= 0, "Can't have a prefix of negative length")
770770
let newCount = min(maxLength, count)
771771
let newSpan = unsafe Self(_unchecked: _pointer, count: newCount)
@@ -788,7 +788,7 @@ extension MutableSpan where Element: ~Copyable {
788788
/// - Complexity: O(1)
789789
@_alwaysEmitIntoClient
790790
@lifetime(borrow self)
791-
mutating public func _extracting(droppingLast k: Int) -> Self {
791+
mutating public func extracting(droppingLast k: Int) -> Self {
792792
_precondition(k >= 0, "Can't drop a negative number of elements")
793793
let droppedCount = min(k, count)
794794
let newCount = count &- droppedCount
@@ -813,7 +813,7 @@ extension MutableSpan where Element: ~Copyable {
813813
/// - Complexity: O(1)
814814
@_alwaysEmitIntoClient
815815
@lifetime(borrow self)
816-
mutating public func _extracting(last maxLength: Int) -> Self {
816+
mutating public func extracting(last maxLength: Int) -> Self {
817817
_precondition(maxLength >= 0, "Can't have a suffix of negative length")
818818
let newCount = min(maxLength, count)
819819
let offset = (count &- newCount) * MemoryLayout<Element>.stride
@@ -838,7 +838,7 @@ extension MutableSpan where Element: ~Copyable {
838838
/// - Complexity: O(1)
839839
@_alwaysEmitIntoClient
840840
@lifetime(borrow self)
841-
mutating public func _extracting(droppingFirst k: Int) -> Self {
841+
mutating public func extracting(droppingFirst k: Int) -> Self {
842842
_precondition(k >= 0, "Can't drop a negative number of elements")
843843
let droppedCount = min(k, count)
844844
let offset = droppedCount * MemoryLayout<Element>.stride

test/stdlib/Span/MutableRawSpanTests.swift

+23-23
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ suite.test("unsafeLoadUnaligned(as:)")
214214
a.withUnsafeMutableBytes {
215215
var span = MutableRawSpan(_unsafeBytes: $0)
216216

217-
let suffix = span._extracting(droppingFirst: 2)
217+
let suffix = span.extracting(droppingFirst: 2)
218218
let u0 = suffix.unsafeLoadUnaligned(as: UInt64.self)
219219
expectEqual(u0 & 0xff, 2)
220220
expectEqual(u0.byteSwapped & 0xff, 9)
@@ -350,7 +350,7 @@ suite.test("update(fromContentsOf:) (contiguous memory)")
350350
expectEqual(a.elementsEqual(0..<capacity), true)
351351
}
352352

353-
suite.test("_extracting()")
353+
suite.test("extracting()")
354354
.skip(.custom(
355355
{ if #available(SwiftStdlib 6.2, *) { false } else { true } },
356356
reason: "Requires Swift 6.2's standard library"
@@ -363,25 +363,25 @@ suite.test("_extracting()")
363363
b.withUnsafeMutableBytes {
364364
var span = MutableRawSpan(_unsafeBytes: $0)
365365

366-
var sub = span._extracting(0..<2)
366+
var sub = span.extracting(0..<2)
367367
expectEqual(sub.byteCount, 2)
368368
expectEqual(sub.unsafeLoad(as: UInt8.self), 0)
369369

370-
sub = span._extracting(..<2)
370+
sub = span.extracting(..<2)
371371
expectEqual(sub.byteCount, 2)
372372
expectEqual(sub.unsafeLoad(as: UInt8.self), 0)
373373

374-
sub = span._extracting(...)
374+
sub = span.extracting(...)
375375
expectEqual(sub.byteCount, 4)
376376
expectEqual(sub.unsafeLoad(as: UInt8.self), 0)
377377

378-
sub = span._extracting(2...)
378+
sub = span.extracting(2...)
379379
expectEqual(sub.byteCount, 2)
380380
expectEqual(sub.unsafeLoad(as: UInt8.self), 2)
381381
}
382382
}
383383

384-
suite.test("_extracting(unchecked:)")
384+
suite.test("extracting(unchecked:)")
385385
.skip(.custom(
386386
{ if #available(SwiftStdlib 6.2, *) { false } else { true } },
387387
reason: "Requires Swift 6.2's standard library"
@@ -393,14 +393,14 @@ suite.test("_extracting(unchecked:)")
393393
var b = (0..<capacity).map(UInt8.init)
394394
b.withUnsafeMutableBytes {
395395
var span = MutableRawSpan(_unsafeBytes: $0.prefix(8))
396-
let beyond = span._extracting(unchecked: 16...23)
396+
let beyond = span.extracting(unchecked: 16...23)
397397
expectEqual(beyond.byteCount, 8)
398398
let fromBeyond = beyond.unsafeLoad(as: UInt8.self)
399399
expectEqual(fromBeyond, 16)
400400
}
401401
}
402402

403-
suite.test("_extracting prefixes")
403+
suite.test("extracting prefixes")
404404
.skip(.custom(
405405
{ if #available(SwiftStdlib 6.2, *) { false } else { true } },
406406
reason: "Requires Swift 6.2's standard library"
@@ -415,19 +415,19 @@ suite.test("_extracting prefixes")
415415
var span = MutableRawSpan(_unsafeBytes: $0)
416416
expectEqual(span.byteCount, capacity)
417417

418-
prefix = span._extracting(first: 1)
418+
prefix = span.extracting(first: 1)
419419
expectEqual(prefix.unsafeLoad(as: UInt8.self), 0)
420420

421-
prefix = span._extracting(first: capacity)
421+
prefix = span.extracting(first: capacity)
422422
expectEqual(
423423
prefix.unsafeLoad(fromByteOffset: capacity-1, as: UInt8.self),
424424
UInt8(capacity-1)
425425
)
426426

427-
prefix = span._extracting(droppingLast: capacity)
427+
prefix = span.extracting(droppingLast: capacity)
428428
expectEqual(prefix.isEmpty, true)
429429

430-
prefix = span._extracting(droppingLast: 1)
430+
prefix = span.extracting(droppingLast: 1)
431431
expectEqual(
432432
prefix.unsafeLoad(fromByteOffset: capacity-2, as: UInt8.self),
433433
UInt8(capacity-2)
@@ -438,12 +438,12 @@ suite.test("_extracting prefixes")
438438
let b = UnsafeMutableRawBufferPointer(start: nil, count: 0)
439439
var span = MutableRawSpan(_unsafeBytes: b)
440440
expectEqual(span.byteCount, b.count)
441-
expectEqual(span._extracting(first: 1).byteCount, b.count)
442-
expectEqual(span._extracting(droppingLast: 1).byteCount, b.count)
441+
expectEqual(span.extracting(first: 1).byteCount, b.count)
442+
expectEqual(span.extracting(droppingLast: 1).byteCount, b.count)
443443
}
444444
}
445445

446-
suite.test("_extracting suffixes")
446+
suite.test("extracting suffixes")
447447
.skip(.custom(
448448
{ if #available(SwiftStdlib 6.2, *) { false } else { true } },
449449
reason: "Requires Swift 6.2's standard library"
@@ -458,27 +458,27 @@ suite.test("_extracting suffixes")
458458
var span = MutableRawSpan(_unsafeBytes: $0)
459459
expectEqual(span.byteCount, capacity)
460460

461-
prefix = span._extracting(last: capacity)
461+
prefix = span.extracting(last: capacity)
462462
expectEqual(prefix.unsafeLoad(as: UInt8.self), 0)
463463

464-
prefix = span._extracting(last: capacity-1)
464+
prefix = span.extracting(last: capacity-1)
465465
expectEqual(prefix.unsafeLoad(as: UInt8.self), 1)
466466

467-
prefix = span._extracting(last: 1)
467+
prefix = span.extracting(last: 1)
468468
expectEqual(prefix.unsafeLoad(as: UInt8.self), UInt8(capacity-1))
469469

470-
prefix = span._extracting(droppingFirst: capacity)
470+
prefix = span.extracting(droppingFirst: capacity)
471471
expectTrue(prefix.isEmpty)
472472

473-
prefix = span._extracting(droppingFirst: 1)
473+
prefix = span.extracting(droppingFirst: 1)
474474
expectEqual(prefix.unsafeLoad(as: UInt8.self), 1)
475475
}
476476

477477
do {
478478
let b = UnsafeMutableRawBufferPointer(start: nil, count: 0)
479479
var span = MutableRawSpan(_unsafeBytes: b)
480480
expectEqual(span.byteCount, b.count)
481-
expectEqual(span._extracting(last: 1).byteCount, b.count)
482-
expectEqual(span._extracting(droppingFirst: 1).byteCount, b.count)
481+
expectEqual(span.extracting(last: 1).byteCount, b.count)
482+
expectEqual(span.extracting(droppingFirst: 1).byteCount, b.count)
483483
}
484484
}

0 commit comments

Comments
 (0)