Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Lukasa opened this issue Jan 9, 2020 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@Lukasa
Copy link
Contributor

Lukasa commented Jan 9, 2020

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
@Lukasa
Copy link
Contributor Author

Lukasa commented Jan 9, 2020

Patch available in #29094

@swift-ci
Copy link
Collaborator

Comment by Kyle Macomber (JIRA)

@swift-ci create

@milseman
Copy link
Mannequin

milseman mannequin commented Jan 22, 2020

Great work @Lukasa!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants