Skip to content

[SR-11999] Substring.UTF8View does not provide an implementation for withContiguousStorageIfAvailable #54434

@Lukasa

Description

@Lukasa
Previous ID SR-11999
Radar rdar://problem/58663804
Original Reporter @Lukasa
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee @milseman
Priority Medium

md5: 0e12af38d6e41ffcc6bfa3efeeec376e

Issue Description:

While String is very good at providing fast access to its backing storage, Substring is less friendly. Try running the program below:

let x = "Hello, world!"

let basePointer = x.utf8.withContiguousStorageIfAvailable {
    UInt(bitPattern: $0.baseAddress!)
}

let slicePointer = x[...].utf8.withContiguousStorageIfAvailable {
    UInt(bitPattern: $0.baseAddress!)
}

if let ptr = basePointer {
    print("✅ String has fast pointer to storage: \(ptr)")
} else {
    print("⚠️  String has no fast pointer to storage")
}

if let ptr = slicePointer {
    print("✅ Substring has fast pointer to storage: \(ptr)")
} else {
    print("⚠️  Substring has no fast pointer to storage")
}

I would expect the output to be:

String has fast pointer to storage: 140732689800216Substring has fast pointer to storage: 140732689800216

But instead I get

String has fast pointer to storage: 140732689800216
⚠️  Substring has no fast pointer to storage

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.standard libraryArea: Standard library umbrella

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions