diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-12 16:17:02 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-12 16:17:02 -0700 |
commit | cfcc753dc8906817e15b1b7c36b4dc12462d12e4 (patch) | |
tree | f5d2aa0caaa4cb336017ba7595c3425f4aa00bfc /lib/btrfs/btrfsitem/item_fileextent.go | |
parent | 29b6b9f997913f13a0bff8bb1278a61302413615 (diff) | |
parent | f76faa4b8debd9c94751a03dd65e46c80a340a82 (diff) |
Merge branch 'lukeshu/fast'
Diffstat (limited to 'lib/btrfs/btrfsitem/item_fileextent.go')
-rw-r--r-- | lib/btrfs/btrfsitem/item_fileextent.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/btrfs/btrfsitem/item_fileextent.go b/lib/btrfs/btrfsitem/item_fileextent.go index 83e5d34..30a14ef 100644 --- a/lib/btrfs/btrfsitem/item_fileextent.go +++ b/lib/btrfs/btrfsitem/item_fileextent.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com> +// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com> // // SPDX-License-Identifier: GPL-2.0-or-later @@ -14,7 +14,7 @@ import ( // key.objectid = inode // key.offset = offset within file -type FileExtent struct { // EXTENT_DATA=108 +type FileExtent struct { // complex EXTENT_DATA=108 Generation btrfsprim.Generation `bin:"off=0x0, siz=0x8"` // transaction ID that created this extent RAMBytes int64 `bin:"off=0x8, siz=0x8"` // upper bound of what compressed data will decompress to @@ -46,6 +46,17 @@ type FileExtentExtent struct { binstruct.End `bin:"off=0x20"` } +func (o *FileExtent) Free() { + bytePool.Put(o.BodyInline) + *o = FileExtent{} + fileExtentPool.Put(o) +} + +func (o FileExtent) Clone() FileExtent { + o.BodyInline = cloneBytes(o.BodyInline) + return o +} + func (o *FileExtent) UnmarshalBinary(dat []byte) (int, error) { n, err := binstruct.UnmarshalWithoutInterface(dat, o) if err != nil { @@ -53,7 +64,7 @@ func (o *FileExtent) UnmarshalBinary(dat []byte) (int, error) { } switch o.Type { case FILE_EXTENT_INLINE: - o.BodyInline = dat[n:] + o.BodyInline = cloneBytes(dat[n:]) n += len(o.BodyInline) case FILE_EXTENT_REG, FILE_EXTENT_PREALLOC: _n, err := binstruct.Unmarshal(dat[n:], &o.BodyExtent) |