[#111712] [Ruby master Feature#19322] Support spawning "private" child processes — "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" <ruby-core@...>
SXNzdWUgIzE5MzIyIGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGtqdHNhbmFrdHNpZGlzIChLSiBUc2Fu
14 messages
2023/01/07
[ruby-core:111685] [Ruby master Feature#19314] String#bytesplice should support partial copy
From:
"Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>
Date:
2023-01-06 13:14:01 UTC
List:
ruby-core #111685
Issue #19314 has been updated by Eregon (Benoit Daloze).
Eregon (Benoit Daloze) wrote in #note-5:
> Now that we have IO::Buffer and there is https://docs.ruby-lang.org/en/master/IO/Buffer.html#method-i-copy, why not use that?
So this does what you want I believe:
```ruby
x = "0123456789"
IO::Buffer.for(x) do |buffer|
buffer.copy(buffer, 2, 3, 6)
end
p x # => "0167856789"
```
I think there is no need to change `String#bytesplice` therefore (there is even not a need for `String#bytesplice` due to that, which [I think we shouldn't have added](https://bugs.ruby-lang.org/issues/18598#note-3)).
And `IO::Buffer` seems better suited for byte-buffer-like operations.
----------------------------------------
Feature #19314: String#bytesplice should support partial copy
https://bugs.ruby-lang.org/issues/19314#change-101081
* 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/