From f67994a77d5bcd7877bf229bfda48e8338f36893 Mon Sep 17 00:00:00 2001 From: Dmitrii Okunev Date: Fri, 31 Jan 2020 20:40:03 +0000 Subject: [PATCH] uefi: Do not copy if not necessary Removed extra copies. It reduces memory consumption, improves performances and simplifies the result. ITS: https://github.com/linuxboot/fiano/issues/304 Signed-off-by: Dmitrii Okunev --- pkg/uefi/biosregion.go | 3 +-- pkg/uefi/file.go | 6 ++---- pkg/uefi/firmwarevolume.go | 5 +---- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/pkg/uefi/biosregion.go b/pkg/uefi/biosregion.go index 13be3b52..71fe2032 100644 --- a/pkg/uefi/biosregion.go +++ b/pkg/uefi/biosregion.go @@ -85,8 +85,7 @@ func NewBIOSRegion(buf []byte, r *FlashRegion, _ FlashRegionType) (Region, error var absOffset uint64 // Copy the buffer - br.buf = make([]byte, len(buf)) - copy(br.buf, buf) + br.buf = buf for { offset := FindFirmwareVolumeOffset(buf) diff --git a/pkg/uefi/file.go b/pkg/uefi/file.go index c0fe9941..3254d537 100644 --- a/pkg/uefi/file.go +++ b/pkg/uefi/file.go @@ -416,10 +416,8 @@ func NewFile(buf []byte) (*File, error) { return nil, fmt.Errorf("File size too big! File with GUID: %v has length %v, but is only %v bytes big", f.Header.GUID, f.Header.ExtendedSize, buflen) } - // Copy out the buffer. - newBuf := buf[:f.Header.ExtendedSize] - f.buf = make([]byte, f.Header.ExtendedSize) - copy(f.buf, newBuf) + + f.buf = buf[:f.Header.ExtendedSize] // Special case for NVAR Store stored in raw file if f.Header.Type == FVFileTypeRaw && f.Header.GUID == *NVAR { diff --git a/pkg/uefi/firmwarevolume.go b/pkg/uefi/firmwarevolume.go index 9f571062..030b81fe 100644 --- a/pkg/uefi/firmwarevolume.go +++ b/pkg/uefi/firmwarevolume.go @@ -259,10 +259,7 @@ func NewFirmwareVolume(data []byte, fvOffset uint64, resizable bool) (*FirmwareV fv.FVType = FVGUIDs[fv.FileSystemGUID] fv.FVOffset = fvOffset - // copy out the buffer. - newBuf := data[:fv.Length] - fv.buf = make([]byte, fv.Length) - copy(fv.buf, newBuf) + fv.buf = data[:fv.Length] // Parse the files. // TODO: handle fv data alignment.