MCPcopy Create free account
hub / github.com/couchbase/moss / optimize

Method optimize

iterator.go:455–483  ·  view source on GitHub ↗

-------------------------------------------- The optimize method tries to optimize an iterator. For example, when there's only a single segment, then the heap can be avoided by using a simpler, faster iteratorSingle implementation.

()

Source from the content-addressed store, hash-verified

453// when there's only a single segment, then the heap can be avoided by
454// using a simpler, faster iteratorSingle implementation.
455func (iter *iterator) optimize() (Iterator, error) {
456 if len(iter.cursors) != 1 {
457 return iter, nil
458 }
459
460 cur := iter.cursors[0]
461
462 if cur.ssIndex == -1 && cur.sc == nil {
463 // Optimization to return lowerLevelIter directly.
464 return iter.lowerLevelIter, nil
465 }
466
467 seg, ok := iter.ss.a[cur.ssIndex].(*segment)
468 if !ok || seg == nil {
469 return iter, nil
470 }
471
472 return &iteratorSingle{
473 s: seg,
474 sc: cur.sc,
475 op: cur.op,
476 k: cur.k,
477 v: cur.v,
478 closer: iter.closer,
479 options: iter.ss.options,
480
481 iteratorOptions: iter.iteratorOptions,
482 }, nil
483}
484
485// --------------------------------------------
486

Callers 1

StartIteratorMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected