-
Couldn't load subscription status.
- Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.standard libraryArea: Standard library umbrellaArea: Standard library umbrella
Description
| 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: 140732689800216
✅ Substring has fast pointer to storage: 140732689800216But instead I get
✅ String has fast pointer to storage: 140732689800216
⚠️ Substring has no fast pointer to storageMetadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.standard libraryArea: Standard library umbrellaArea: Standard library umbrella