From 0d4f16b6baa65a74fce36755ba71ed97eb22d230 Mon Sep 17 00:00:00 2001 From: greatroar <@> Date: Mon, 7 Jun 2021 19:45:45 +0200 Subject: [PATCH] Return s3.fileInfos by pointer Since the fileInfos are returned in a []interface, they're already allocated on the heap. Making them pointers explicitly means the compiler doesn't need to generate fileInfo and *fileInfo versions of the methods on this type. The binary becomes about 7KiB smaller on Linux/amd64. --- internal/backend/s3/s3.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/backend/s3/s3.go b/internal/backend/s3/s3.go index 044d39c5c..6fee1fd66 100644 --- a/internal/backend/s3/s3.go +++ b/internal/backend/s3/s3.go @@ -186,12 +186,12 @@ type fileInfo struct { isDir bool } -func (fi fileInfo) Name() string { return fi.name } // base name of the file -func (fi fileInfo) Size() int64 { return fi.size } // length in bytes for regular files; system-dependent for others -func (fi fileInfo) Mode() os.FileMode { return fi.mode } // file mode bits -func (fi fileInfo) ModTime() time.Time { return fi.modTime } // modification time -func (fi fileInfo) IsDir() bool { return fi.isDir } // abbreviation for Mode().IsDir() -func (fi fileInfo) Sys() interface{} { return nil } // underlying data source (can return nil) +func (fi *fileInfo) Name() string { return fi.name } // base name of the file +func (fi *fileInfo) Size() int64 { return fi.size } // length in bytes for regular files; system-dependent for others +func (fi *fileInfo) Mode() os.FileMode { return fi.mode } // file mode bits +func (fi *fileInfo) ModTime() time.Time { return fi.modTime } // modification time +func (fi *fileInfo) IsDir() bool { return fi.isDir } // abbreviation for Mode().IsDir() +func (fi *fileInfo) Sys() interface{} { return nil } // underlying data source (can return nil) // ReadDir returns the entries for a directory. func (be *Backend) ReadDir(ctx context.Context, dir string) (list []os.FileInfo, err error) { @@ -225,7 +225,7 @@ func (be *Backend) ReadDir(ctx context.Context, dir string) (list []os.FileInfo, if name == "" { continue } - entry := fileInfo{ + entry := &fileInfo{ name: name, size: obj.Size, modTime: obj.LastModified,