@@ -23,21 +23,21 @@ 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 highlightStyle = style .FgLightWhite .SetBold ()
35
35
36
- func (self Pipe ) left () int {
36
+ func (self Pipe ) left () int16 {
37
37
return min (self .fromPos , self .toPos )
38
38
}
39
39
40
- func (self Pipe ) right () int {
40
+ func (self Pipe ) right () int16 {
41
41
return max (self .fromPos , self .toPos )
42
42
}
43
43
@@ -103,7 +103,7 @@ func RenderAux(pipeSets [][]Pipe, commits []*models.Commit, selectedCommitHash *
103
103
}
104
104
105
105
func getNextPipes (hashPool * utils.StringPool , prevPipes []Pipe , commit * models.Commit , getStyle func (c * models.Commit ) * style.TextStyle ) []Pipe {
106
- maxPos := 0
106
+ maxPos := int16 ( 0 )
107
107
for _ , pipe := range prevPipes {
108
108
if pipe .toPos > maxPos {
109
109
maxPos = pipe .toPos
@@ -129,6 +129,9 @@ func getNextPipes(hashPool *utils.StringPool, prevPipes []Pipe, commit *models.C
129
129
}
130
130
131
131
// a taken spot is one where a current pipe is ending on
132
+ // Note: this set and similar ones below use int instead of int16 because
133
+ // that's much more efficient. We cast the int16 values we store in these
134
+ // sets to int on every access.
132
135
takenSpots := set .New [int ]()
133
136
// a traversed spot is one where a current pipe is starting on, ending on, or passing through
134
137
traversedSpots := set .New [int ]()
@@ -156,41 +159,41 @@ func getNextPipes(hashPool *utils.StringPool, prevPipes []Pipe, commit *models.C
156
159
traversedSpotsForContinuingPipes := set .New [int ]()
157
160
for _ , pipe := range currentPipes {
158
161
if ! equalHashes (pipe .toHash , commit .Hash ) {
159
- traversedSpotsForContinuingPipes .Add (pipe .toPos )
162
+ traversedSpotsForContinuingPipes .Add (int ( pipe .toPos ) )
160
163
}
161
164
}
162
165
163
- getNextAvailablePosForContinuingPipe := func () int {
164
- i := 0
166
+ getNextAvailablePosForContinuingPipe := func () int16 {
167
+ i := int16 ( 0 )
165
168
for {
166
- if ! traversedSpots .Includes (i ) {
169
+ if ! traversedSpots .Includes (int ( i ) ) {
167
170
return i
168
171
}
169
172
i ++
170
173
}
171
174
}
172
175
173
- getNextAvailablePosForNewPipe := func () int {
174
- i := 0
176
+ getNextAvailablePosForNewPipe := func () int16 {
177
+ i := int16 ( 0 )
175
178
for {
176
179
// a newly created pipe is not allowed to end on a spot that's already taken,
177
180
// nor on a spot that's been traversed by a continuing pipe.
178
- if ! takenSpots .Includes (i ) && ! traversedSpotsForContinuingPipes .Includes (i ) {
181
+ if ! takenSpots .Includes (int ( i )) && ! traversedSpotsForContinuingPipes .Includes (int ( i ) ) {
179
182
return i
180
183
}
181
184
i ++
182
185
}
183
186
}
184
187
185
- traverse := func (from , to int ) {
188
+ traverse := func (from , to int16 ) {
186
189
left , right := from , to
187
190
if left > right {
188
191
left , right = right , left
189
192
}
190
193
for i := left ; i <= right ; i ++ {
191
- traversedSpots .Add (i )
194
+ traversedSpots .Add (int ( i ) )
192
195
}
193
- takenSpots .Add (to )
196
+ takenSpots .Add (int ( to ) )
194
197
}
195
198
196
199
for _ , pipe := range currentPipes {
@@ -233,7 +236,7 @@ func getNextPipes(hashPool *utils.StringPool, prevPipes []Pipe, commit *models.C
233
236
style : getStyle (commit ),
234
237
})
235
238
236
- takenSpots .Add (availablePos )
239
+ takenSpots .Add (int ( availablePos ) )
237
240
}
238
241
}
239
242
@@ -242,7 +245,7 @@ func getNextPipes(hashPool *utils.StringPool, prevPipes []Pipe, commit *models.C
242
245
// continuing on, potentially moving left to fill in a blank spot
243
246
last := pipe .toPos
244
247
for i := pipe .toPos ; i > pos ; i -- {
245
- if takenSpots .Includes (i ) || traversedSpots .Includes (i ) {
248
+ if takenSpots .Includes (int ( i )) || traversedSpots .Includes (int ( i ) ) {
246
249
break
247
250
} else {
248
251
last = i
@@ -276,8 +279,8 @@ func renderPipeSet(
276
279
selectedCommitHash * string ,
277
280
prevCommit * models.Commit ,
278
281
) string {
279
- maxPos := 0
280
- commitPos := 0
282
+ maxPos := int16 ( 0 )
283
+ commitPos := int16 ( 0 )
281
284
startCount := 0
282
285
for _ , pipe := range pipes {
283
286
if pipe .kind == STARTS {
@@ -293,7 +296,7 @@ func renderPipeSet(
293
296
}
294
297
isMerge := startCount > 1
295
298
296
- cells := lo .Map (lo .Range (maxPos + 1 ), func (i int , _ int ) * Cell {
299
+ cells := lo .Map (lo .Range (int ( maxPos ) + 1 ), func (i int , _ int ) * Cell {
297
300
return & Cell {cellType : CONNECTION , style : & style .FgDefault }
298
301
})
299
302
0 commit comments