Skip to content
Myr

Fix #151 - reduce initial memory footprint

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 6130026 · Browse files · 2 files+27 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+27 added−1 removed

  • other:+27 added−1 removed

2 files+27 added−1 removed

modified:src/matcher.go+4 added
132 unmodified lines
133 return EmptyMerger, false134 }135 pattern := request.pattern136 empty := pattern.IsEmpty()137 if empty {138 return PassMerger(&request.chunks, m.tac), false139 }140141 cancelled := util.NewAtomicBool(false)142143 slices := m.sliceChunks(request.chunks)144 numSlices := len(slices)
78 unmodified lines
modified:src/merger.go+23 added-1 removed
8 unmodified lines
9// a single, globally-sorted list10type Merger struct {11 lists [][]*Item12 merged []*Item13 chunks *[]*Chunk14 cursors []int15 sorted bool16 tac bool17 final bool18 count int19}2021func PassMerger(chunks *[]*Chunk, tac bool) *Merger {22 mg := Merger{23 chunks: chunks,24 tac: tac,25 count: 0}2627 for _, chunk := range *mg.chunks {28 mg.count += len(*chunk)29 }30 return &mg31}3233// NewMerger returns a new Merger34func NewMerger(lists [][]*Item, sorted bool, tac bool) *Merger {35 mg := Merger{36 lists: lists,37 merged: []*Item{},38 chunks: nil,39 cursors: make([]int, len(lists)),40 sorted: sorted,41 tac: tac,42 final: false,
11 unmodified lines
54}5556// Get returns the pointer to the Item object indexed by the given integer57func (mg *Merger) Get(idx int) *Item {58 if mg.chunks != nil {59 if mg.tac {60 idx = mg.count - idx - 161 }62 chunk := (*mg.chunks)[idx/ChunkSize]63 return (*chunk)[idx%ChunkSize]64 }6566 if mg.sorted {67 return mg.mergedGet(idx)68 }6970 if mg.tac {49 idx = mg.Length() - idx - 171 idx = mg.count - idx - 172 }73 for _, list := range mg.lists {74 numItems := len(list)75 if idx < numItems {
37 unmodified lines