Skip to content

Commit 3853ad3

Browse files
ndeloofglours
authored andcommitted
prefer *task for memory efficiency updating tasks
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 02008a0 commit 3853ad3

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

cmd/display/tty.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626
"time"
2727

2828
"github.com/buger/goterm"
29-
"github.com/docker/compose/v5/pkg/utils"
3029
"github.com/docker/go-units"
3130
"github.com/morikuni/aec"
3231

3332
"github.com/docker/compose/v5/pkg/api"
33+
"github.com/docker/compose/v5/pkg/utils"
3434
)
3535

3636
// Full creates an EventProcessor that render advanced UI within a terminal.
@@ -39,7 +39,7 @@ func Full(out io.Writer, info io.Writer) api.EventProcessor {
3939
return &ttyWriter{
4040
out: out,
4141
info: info,
42-
tasks: map[string]task{},
42+
tasks: map[string]*task{},
4343
done: make(chan bool),
4444
mtx: &sync.Mutex{},
4545
}
@@ -48,7 +48,7 @@ func Full(out io.Writer, info io.Writer) api.EventProcessor {
4848
type ttyWriter struct {
4949
out io.Writer
5050
ids []string // tasks ids ordered as first event appeared
51-
tasks map[string]task
51+
tasks map[string]*task
5252
repeated bool
5353
numLines int
5454
done chan bool
@@ -208,10 +208,9 @@ func (w *ttyWriter) event(e api.Resource) {
208208

209209
if last, ok := w.tasks[e.ID]; ok {
210210
last.update(e)
211-
w.tasks[e.ID] = last
212211
} else {
213212
t := newTask(e)
214-
w.tasks[e.ID] = t
213+
w.tasks[e.ID] = &t
215214
w.ids = append(w.ids, e.ID)
216215
}
217216
w.printEvent(e)
@@ -237,8 +236,8 @@ func (w *ttyWriter) printEvent(e api.Resource) {
237236
_, _ = fmt.Fprintf(w.out, "%s %s %s\n", e.ID, color(e.Text), e.Details)
238237
}
239238

240-
func (w *ttyWriter) parentTasks() iter.Seq[task] {
241-
return func(yield func(task) bool) {
239+
func (w *ttyWriter) parentTasks() iter.Seq[*task] {
240+
return func(yield func(*task) bool) {
242241
for _, id := range w.ids { // iterate on ids to enforce a consistent order
243242
t := w.tasks[id]
244243
if len(t.parents) == 0 {
@@ -248,8 +247,8 @@ func (w *ttyWriter) parentTasks() iter.Seq[task] {
248247
}
249248
}
250249

251-
func (w *ttyWriter) childrenTasks(parent string) iter.Seq[task] {
252-
return func(yield func(task) bool) {
250+
func (w *ttyWriter) childrenTasks(parent string) iter.Seq[*task] {
251+
return func(yield func(*task) bool) {
253252
for _, id := range w.ids { // iterate on ids to enforce a consistent order
254253
t := w.tasks[id]
255254
if t.parents.Has(parent) {
@@ -316,7 +315,7 @@ func (w *ttyWriter) print() {
316315
w.numLines = numLines
317316
}
318317

319-
func (w *ttyWriter) lineText(t task, pad string, terminalWidth, statusPadding int, dryRun bool) string {
318+
func (w *ttyWriter) lineText(t *task, pad string, terminalWidth, statusPadding int, dryRun bool) string {
320319
endTime := time.Now()
321320
if t.status != api.Working {
322321
endTime = t.startTime
@@ -403,7 +402,7 @@ var (
403402
spinnerError = "✘"
404403
)
405404

406-
func spinner(t task) string {
405+
func spinner(t *task) string {
407406
switch t.status {
408407
case api.Done:
409408
return SuccessColor(spinnerDone)
@@ -429,7 +428,7 @@ func colorFn(s api.EventStatus) colorFunc {
429428
}
430429
}
431430

432-
func numDone(tasks map[string]task) int {
431+
func numDone(tasks map[string]*task) int {
433432
i := 0
434433
for _, t := range tasks {
435434
if t.status != api.Working {

0 commit comments

Comments
 (0)