From 67ce1a9c2eb748a47a1bd6d73ca4c9c9a15d42ae Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Sun, 19 Mar 2023 22:21:02 -0700 Subject: [PATCH] filelist/initramfs: cache list of files (MR 34) Allows subsequent calls to List() to return quickly --- internal/filelist/initramfs/initramfs.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/filelist/initramfs/initramfs.go b/internal/filelist/initramfs/initramfs.go index f119c36..0cd48a2 100644 --- a/internal/filelist/initramfs/initramfs.go +++ b/internal/filelist/initramfs/initramfs.go @@ -9,6 +9,7 @@ import ( // combining the output from them. type Initramfs struct { features []filelist.FileLister + files *filelist.FileList } // New returns a new Initramfs that generate a list of files based on the given @@ -20,15 +21,18 @@ func New(features []filelist.FileLister) *Initramfs { } func (i *Initramfs) List() (*filelist.FileList, error) { - files := filelist.NewFileList() + if i.files != nil { + return i.files, nil + } + i.files = filelist.NewFileList() for _, f := range i.features { list, err := f.List() if err != nil { return nil, err } - files.Import(list) + i.files.Import(list) } - return files, nil + return i.files, nil }