Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
- Feature Name: String split zero-copy | ||
- Start Date: 2016-10-18 | ||
- RFC PR: | ||
- Pony Issue: | ||
|
||
# Summary | ||
|
||
The string splitting method should work on an immutable copy and provide a "zero-copy" functionality. | ||
|
||
# Motivation | ||
|
||
This behavior is preferable because you get to decide whether to make zero or one copy of the complete string. It's easy to obtain an immutable copy of a string so usability is preserved. | ||
|
||
# Detailed design | ||
|
||
The splitting method will be revised to operate on the immutable string only, returning immutable zero-copy reference strings to the same memory allocation. | ||
|
||
Typical usage: | ||
```pony | ||
let words = "Hello world".split() | ||
let s = "1,2,3".clone() | ||
let numbers = s.split(",") | ||
``` | ||
The latter example relies on auto-recover to make the cloned ``String iso`` immutable. | ||
|
||
# How We Teach This | ||
|
||
This API is a good candidate for inclusion in the tutorial. It's a common operation and it highlights how reference capabilities fit naturally in library design. | ||
|
||
# How We Test This | ||
|
||
The existing tests will be adapted. | ||
|
||
#### Drawbacks #### | ||
|
||
This breaks existing code. | ||
|
||
# Alternatives | ||
|
||
Not considered. | ||
|
||
# Unresolved questions | ||
|
||
No open questions. |