mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-22789 Fix typos, add TODOs for future optimization design
This commit is contained in:
parent
4163a6d898
commit
d9017e0408
2 changed files with 17 additions and 10 deletions
|
@ -11,14 +11,6 @@ public interface Segments {
|
|||
|
||||
Stream<Segment> ranges();
|
||||
|
||||
/**
|
||||
* Returns whether offset {@code i} is a segmentation boundary. Throws an exception when
|
||||
* {@code i} is not a valid boundary position for the source sequence.
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
boolean isBoundary(int i);
|
||||
|
||||
Stream<Segment> rangesAfterIndex(int i);
|
||||
|
||||
Stream<Segment> rangesBeforeIndex(int i);
|
||||
|
@ -29,6 +21,14 @@ public interface Segments {
|
|||
|
||||
Function<Segment, CharSequence> rangeToSequenceFn();
|
||||
|
||||
/**
|
||||
* Returns whether offset {@code i} is a segmentation boundary. Throws an exception when
|
||||
* {@code i} is not a valid boundary position for the source sequence.
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
boolean isBoundary(int i);
|
||||
|
||||
IntStream boundaries();
|
||||
|
||||
IntStream boundariesAfter(int i);
|
||||
|
@ -48,16 +48,21 @@ public interface Segments {
|
|||
// Inner classes for Segment, SegmentIterable, and SegmentIterator
|
||||
//
|
||||
|
||||
// TODO: consider options in design for potential memory usage optimization:
|
||||
// 1) keep simple class with public fields, but requires field per Segment to point to source
|
||||
// 2) make Segment an interface (getSource, getStart, getLimit, getRuleStatus, newSegment), and
|
||||
// maybe an abstract class that implements the interface, maybe with a default method impl
|
||||
// for convenience for getting (allocating & returning) the subsequence
|
||||
class Segment {
|
||||
public final int start;
|
||||
public final int limit;
|
||||
public final int ruleStatus = 0;
|
||||
public final CharSequence soruce;
|
||||
public final CharSequence source;
|
||||
|
||||
public Segment(int start, int limit, CharSequence source) {
|
||||
this.start = start;
|
||||
this.limit = limit;
|
||||
this.soruce = source;
|
||||
this.source = source;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,6 +94,7 @@ public class SegmentsImplUtils {
|
|||
breakIter.setText(sourceSequence);
|
||||
|
||||
// create a Stream from a Spliterator of an Iterable so that the Stream can be lazy, not eager
|
||||
// TODO: optimize IntStream creation to avoid autoboxing
|
||||
BoundaryIterable iterable = new BoundaryIterable(breakIter, IterationDirection.FORWARDS, i);
|
||||
Stream<Integer> boundariesAsIntegers = StreamSupport.stream(iterable.spliterator(), false);
|
||||
return boundariesAsIntegers.mapToInt(Integer::intValue);
|
||||
|
@ -112,6 +113,7 @@ public class SegmentsImplUtils {
|
|||
int backFromIdx = isOnBoundary ? i + 1 : i;
|
||||
|
||||
// create a Stream from a Spliterator of an Iterable so that the Stream can be lazy, not eager
|
||||
// TODO: optimize IntStream creation to avoid autoboxing
|
||||
BoundaryIterable iterable = new BoundaryIterable(breakIter, IterationDirection.BACKWARDS, backFromIdx);
|
||||
Stream<Integer> boundariesAsIntegers = StreamSupport.stream(iterable.spliterator(), false);
|
||||
return boundariesAsIntegers.mapToInt(Integer::intValue);
|
||||
|
|
Loading…
Add table
Reference in a new issue