From: "naruse (Yui NARUSE) via ruby-core" Date: 2023-01-06T12:41:30+00:00 Subject: [ruby-core:111680] [Ruby master Feature#19314] String#bytesplice should support partial copy Issue #19314 has been updated by naruse (Yui NARUSE). I agree that this is a workaround and a VM should solve this as an optimization. But your proposal: Lazy substrings is not a solution because it also creates an object especially for small strings which is embedded in RVALUE. I agree that this is memcpy/arraycopy. Therefore this proposal should add a description how large this workaround contributes performance in such use cases as memcpy on Ruby. ---------------------------------------- Feature #19314: String#bytesplice should support partial copy https://bugs.ruby-lang.org/issues/19314#change-101075 * Author: shugo (Shugo Maeda) * Status: Open * Priority: Normal ---------------------------------------- String#bytesplice should support partial copy without temporary String objects. For example, given `x = "0123456789"`, either of the following replaces the contents of `x` with `"0167856789"`: ```ruby x.bytesplice(2, 3, x, 6, 3) x.bytesplice(2..4, x, 6..8) ``` ## Considerations * What should be the return value? * The return value should be the whole source string for performance and consistency with `bytesplice(offset, len, s)`. * Can the source and destination ranges overlap? * Yes. * Can the source and destination lengths be different? * Yes. * Can range form and offset/length form be mixed in the source and destination? * No. * What should happen when any offset doesn't land on character boundary in text strings. * IndexError should be raised. * Can the length be omitted in the destination? * Maybe yes, but it may be confusing. ## Use cases * [Gapped buffer implementation for text editors](https://github.com/shugo/textbringer) * [NAT implementation](https://github.com/kazuho/rat) * https://twitter.com/kazuho/status/1611279616098070532 -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/