// Finds out the index of a sublist in the original list // Works with nested (grand-parent) sublists. // Does not work with lists not made with subList() (returns -1) static int magicIndexOfSubList(L list, L sublist) { if (sublist == list) ret 0; ifdef OurSubLists if (sublist cast ISubList) { L root = sublist.rootList(); int o2 = sublist.subListOffset(); if (list cast ISubList) { if (list.rootList() != root) ret -1; L o1 = list.subListOffset(); ret o2-o1; } else { if (list != root) ret -1; ret o2; } } ret -1; endif ifndef OurSubLists Int o2 = cast get(sublist, "offset"); if (o2 == null) ret -1; Int o1 = cast getOpt(list, "offset"); ret o2-(o1 != null ? o1 : 0); endifndef }