Closed hawkw closed 7 years ago
Performance is very slightly worse than when we used to only support char
-based indexing, by a constant factor of about 200 ms. I think there's some room for optimisation in there, since given that Metric
is almost entirely trait based, it should be a zero-cost abstraction. Note that benchmark results is significantly better than the current master
(8dd43f3d09444fe1ed69e57fc6d2e23204b4386f), where ALL indexing is along Grapheme
s.
This also still needs support for tendril
– it should be trivial to add Measured
implementations for StrTendril
s. Currently I haven't added that yet, since tendril
support was already broken on the master
this branch was forked from (see #63).
this is awesomesauce, will check it out as soon as i can, but great work
I think this should push either a patch (v0.0.4) or a minor version (v0.1.0) when it hits master
?
I suspect that a lot of the boilerplate in here could be reduced with the newtype-derive
crate...
@cjm00: I'm working on adding docs to get this ready to merge, but I've hit a couple of bugs that still need to be fixed, so it might take slightly longer.
It looks like 40964669918197fa92b645769b3766abe2f75c67 also fixes #65; that was supposed to go on master
but I committed it to my dev branch by mistake :sweat:
No coverage report found for master at 8dd43f3.
Powered by Codecov. Last update 8dd43f3...d808848
This PR extends the existing
Rope
metrics system to make allRope
methods optionally parameterised withMetric
s. This allows you tosplit
,insert
, ordelete
Ropes on character, line, or grapheme indices, without adding a whole bunch of new, wordy method names likesplit_on_grapheme_index
and so on.For example, if I wanted to delete characters 5 to 15 from rope r, I could say:
but if I actually wanted to delete graphemes 5 to 15, I could instead say:
or even
Note how the use of a newtype to represent indices along a metric, allowing for nicely natural language-like syntax (e.g.
Line(5)
, which is pretty close to the English "line 5").Metric
is implemented forusize
, which is the "default" char-based metric. This way, this PR is backwards compatible with most of our existing code, andMetric
-based operations nicely default to char-based indexing when used with number literals.Things that are still needed:
Metric
module needs some docs explaining how this works!)delete
ing by line that @twisted-pear wrote also work, but we need more comprehensive tests for various metrics)RopeSlice
s don't currently support slicingMetric
ranges, liker.slice(Line(3)..Line(6))
.