ceylon-sdk icon indicating copy to clipboard operation
ceylon-sdk copied to clipboard

Optimize JSON Array span methods

Open jvasileff opened this issue 11 years ago • 6 comments

JSON Array.span, spanFrom, and spanTo currently leverage the underlying LinkedLists span methods:

    shared actual Array span(Integer from, Integer to) 
            => Array(list.span(from, to));

But list.span creates a copy of the list, as does the Array constructor. I suppose a non-shared constructor that skips the final copy could be used here.

jvasileff avatar Dec 28 '14 18:12 jvasileff

Not sure if this is intentional or not, but reversed and rest are eager, despite List calling for lazy views.

jvasileff avatar Dec 28 '14 23:12 jvasileff

Not sure if this is intentional or not, but reversed and rest are eager, despite List calling for lazy views.

OK, we should fix that.

gavinking avatar Dec 28 '14 23:12 gavinking

@jvasileff the problem is that LinkedList.span() * et. al.* are declared to return a plain List, but the rest of Array needs the list to be a LinkedList or at least MutableList, so a non-shared constructor it not sufficient: We'd need to refine the return type of span() etc on LinkedList (or MutableList) as well.

tombentley avatar Sep 29 '15 12:09 tombentley

@tombentley alternatively you could just use sublist(), which returns something like a span without copying.

LinkedList.sublist() is currently not very efficient, but that's something on my list of things to optimize.

gavinking avatar Sep 29 '15 12:09 gavinking

FTR: see #423.

gavinking avatar Sep 29 '15 16:09 gavinking

Moving to 1.3

FroMage avatar Oct 12 '15 14:10 FroMage