an-cabal/an-rope

Consider chunking the string in `Rope::from(String)`

Closed this issue · 2 comments

hawkw commented

Currently, when we create a new Rope from a String, we put the whole string in one Leaf node. That means that indexing-based operations will initially have roughly the same time overhead as indexing a String, and we won't see performance improvements until the Rope has been appended or inserted into enough to turn it into a nice tree structure. We might want to consider having the Rope::from<String> implementation split the string into chunks so that we can reap Rope performance benefits immediately.

hawkw commented

One way to do this that springs initially to mind is to create an unbalanced branch as the root node, rather than a leaf, and then call .rebalance() on it. If we were to, say, put the whole string in the left child of a branch and then rebalance that node immediately, we'd end up with a nice, balanced tree using our already existing .rebalance() method.

Of course, this may not be the best way to do this, but it was the obvious way, to me.

hawkw commented

@cjm00, what do you think?