Skip to content

Commit

Permalink
uefi: Do not copy if not necessary
Browse files Browse the repository at this point in the history
Removed extra copies. It reduces memory consumption,
improves performances and simplifies the result.

ITS: linuxboot#304

Signed-off-by: Dmitrii Okunev <[email protected]>
  • Loading branch information
xaionaro committed Jan 31, 2020
1 parent a816cc9 commit 164658f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
4 changes: 1 addition & 3 deletions pkg/uefi/biosregion.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ func NewBIOSRegion(buf []byte, r *FlashRegion, _ FlashRegionType) (Region, error
RegionType: RegionTypeBIOS}
var absOffset uint64

// Copy the buffer
br.buf = make([]byte, len(buf))
copy(br.buf, buf)
br.buf = buf

for {
offset := FindFirmwareVolumeOffset(buf)
Expand Down
6 changes: 2 additions & 4 deletions pkg/uefi/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions pkg/uefi/firmwarevolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 164658f

Please sign in to comment.