@@ -23,12 +23,12 @@ const (
23
23
)
24
24
25
25
type Pipe struct {
26
- fromPos int
27
- toPos int
28
26
fromHash * string
29
27
toHash * string
30
- kind PipeKind
31
28
style * style.TextStyle
29
+ fromPos int16
30
+ toPos int16
31
+ kind PipeKind
32
32
}
33
33
34
34
var (
@@ -37,11 +37,11 @@ var (
37
37
StartCommitHash = "START"
38
38
)
39
39
40
- func (self Pipe ) left () int {
40
+ func (self Pipe ) left () int16 {
41
41
return min (self .fromPos , self .toPos )
42
42
}
43
43
44
- func (self Pipe ) right () int {
44
+ func (self Pipe ) right () int16 {
45
45
return max (self .fromPos , self .toPos )
46
46
}
47
47
@@ -107,7 +107,7 @@ func RenderAux(pipeSets [][]Pipe, commits []*models.Commit, selectedCommitHash *
107
107
}
108
108
109
109
func getNextPipes (prevPipes []Pipe , commit * models.Commit , getStyle func (c * models.Commit ) * style.TextStyle ) []Pipe {
110
- maxPos := 0
110
+ maxPos := int16 ( 0 )
111
111
for _ , pipe := range prevPipes {
112
112
if pipe .toPos > maxPos {
113
113
maxPos = pipe .toPos
@@ -133,6 +133,9 @@ func getNextPipes(prevPipes []Pipe, commit *models.Commit, getStyle func(c *mode
133
133
}
134
134
135
135
// a taken spot is one where a current pipe is ending on
136
+ // Note: this set and similar ones below use int instead of int16 because
137
+ // that's much more efficient. We cast the int16 values we store in these
138
+ // sets to int on every access.
136
139
takenSpots := set .New [int ]()
137
140
// a traversed spot is one where a current pipe is starting on, ending on, or passing through
138
141
traversedSpots := set .New [int ]()
@@ -155,41 +158,41 @@ func getNextPipes(prevPipes []Pipe, commit *models.Commit, getStyle func(c *mode
155
158
traversedSpotsForContinuingPipes := set .New [int ]()
156
159
for _ , pipe := range currentPipes {
157
160
if ! equalHashes (pipe .toHash , commit .HashPtr ()) {
158
- traversedSpotsForContinuingPipes .Add (pipe .toPos )
161
+ traversedSpotsForContinuingPipes .Add (int ( pipe .toPos ) )
159
162
}
160
163
}
161
164
162
- getNextAvailablePosForContinuingPipe := func () int {
163
- i := 0
165
+ getNextAvailablePosForContinuingPipe := func () int16 {
166
+ i := int16 ( 0 )
164
167
for {
165
- if ! traversedSpots .Includes (i ) {
168
+ if ! traversedSpots .Includes (int ( i ) ) {
166
169
return i
167
170
}
168
171
i ++
169
172
}
170
173
}
171
174
172
- getNextAvailablePosForNewPipe := func () int {
173
- i := 0
175
+ getNextAvailablePosForNewPipe := func () int16 {
176
+ i := int16 ( 0 )
174
177
for {
175
178
// a newly created pipe is not allowed to end on a spot that's already taken,
176
179
// nor on a spot that's been traversed by a continuing pipe.
177
- if ! takenSpots .Includes (i ) && ! traversedSpotsForContinuingPipes .Includes (i ) {
180
+ if ! takenSpots .Includes (int ( i )) && ! traversedSpotsForContinuingPipes .Includes (int ( i ) ) {
178
181
return i
179
182
}
180
183
i ++
181
184
}
182
185
}
183
186
184
- traverse := func (from , to int ) {
187
+ traverse := func (from , to int16 ) {
185
188
left , right := from , to
186
189
if left > right {
187
190
left , right = right , left
188
191
}
189
192
for i := left ; i <= right ; i ++ {
190
- traversedSpots .Add (i )
193
+ traversedSpots .Add (int ( i ) )
191
194
}
192
- takenSpots .Add (to )
195
+ takenSpots .Add (int ( to ) )
193
196
}
194
197
195
198
for _ , pipe := range currentPipes {
@@ -232,7 +235,7 @@ func getNextPipes(prevPipes []Pipe, commit *models.Commit, getStyle func(c *mode
232
235
style : getStyle (commit ),
233
236
})
234
237
235
- takenSpots .Add (availablePos )
238
+ takenSpots .Add (int ( availablePos ) )
236
239
}
237
240
}
238
241
@@ -241,7 +244,7 @@ func getNextPipes(prevPipes []Pipe, commit *models.Commit, getStyle func(c *mode
241
244
// continuing on, potentially moving left to fill in a blank spot
242
245
last := pipe .toPos
243
246
for i := pipe .toPos ; i > pos ; i -- {
244
- if takenSpots .Includes (i ) || traversedSpots .Includes (i ) {
247
+ if takenSpots .Includes (int ( i )) || traversedSpots .Includes (int ( i ) ) {
245
248
break
246
249
} else {
247
250
last = i
@@ -275,8 +278,8 @@ func renderPipeSet(
275
278
selectedCommitHash * string ,
276
279
prevCommit * models.Commit ,
277
280
) string {
278
- maxPos := 0
279
- commitPos := 0
281
+ maxPos := int16 ( 0 )
282
+ commitPos := int16 ( 0 )
280
283
startCount := 0
281
284
for _ , pipe := range pipes {
282
285
if pipe .kind == STARTS {
@@ -292,7 +295,7 @@ func renderPipeSet(
292
295
}
293
296
isMerge := startCount > 1
294
297
295
- cells := lo .Map (lo .Range (maxPos + 1 ), func (i int , _ int ) * Cell {
298
+ cells := lo .Map (lo .Range (int ( maxPos ) + 1 ), func (i int , _ int ) * Cell {
296
299
return & Cell {cellType : CONNECTION , style : & style .FgDefault }
297
300
})
298
301
0 commit comments