Skip to content

Commit

Permalink
String split zero copy
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed Oct 18, 2016
1 parent f8aefe4 commit d9be53d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions text/0000-string-split-zero-copy.md
@@ -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.

0 comments on commit d9be53d

Please sign in to comment.