Project

General

Profile

Actions

Feature #19315

open

Lazy substrings in CRuby

Added by Eregon (Benoit Daloze) over 1 year ago. Updated 11 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:111678]

Description

CRuby should implement lazy substrings, i.e., "abcdef"[1..3] must not copy bytes.

Currently CRuby only reuse the char* if the substring is until the end of the buffer.
But it should also work wherever the substring starts and ends.
Yes, it means RSTRING_PTR() might need to allocate to \0-terminate, so be it, it's worth it.

There is already code for this (SHARABLE_MIDDLE_SUBSTRING), but it's disabled by default and RSTRING_PTR() needs to be changed to deal with this.
It seems a good idea to introduce a variant of RSTRING_PTR which doesn't guarantee \0-termination, so such callers can then use the existing bytes always without copy.

There are countless workarounds for this missing optimization, all not worth it with lazy substring and all less readable:


Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #19314: String#bytesplice should support partial copyClosedActions
Related to Ruby master - Feature #18598: Add String#bytespliceClosedActions
Actions

Also available in: Atom PDF

Like2
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0