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_dir.go | |
parent | 29b6b9f997913f13a0bff8bb1278a61302413615 (diff) | |
parent | f76faa4b8debd9c94751a03dd65e46c80a340a82 (diff) |
Merge branch 'lukeshu/fast'
Diffstat (limited to 'lib/btrfs/btrfsitem/item_dir.go')
-rw-r--r-- | lib/btrfs/btrfsitem/item_dir.go | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/btrfs/btrfsitem/item_dir.go b/lib/btrfs/btrfsitem/item_dir.go index 584e44d..0049072 100644 --- a/lib/btrfs/btrfsitem/item_dir.go +++ b/lib/btrfs/btrfsitem/item_dir.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 @@ -23,7 +23,7 @@ func NameHash(dat []byte) uint64 { // key.offset = // - for DIR_ITEM and XATTR_ITEM = NameHash(name) // - for DIR_INDEX = index id in the directory (starting at 2, because "." and "..") -type DirEntry struct { // DIR_ITEM=84 DIR_INDEX=96 XATTR_ITEM=24 +type DirEntry struct { // complex DIR_ITEM=84 DIR_INDEX=96 XATTR_ITEM=24 Location btrfsprim.Key `bin:"off=0x0, siz=0x11"` TransID int64 `bin:"off=0x11, siz=8"` DataLen uint16 `bin:"off=0x19, siz=2"` // [ignored-when-writing] @@ -34,6 +34,19 @@ type DirEntry struct { // DIR_ITEM=84 DIR_INDEX=96 XATTR_ITEM=24 Name []byte `bin:"-"` } +func (o *DirEntry) Free() { + bytePool.Put(o.Data) + bytePool.Put(o.Name) + *o = DirEntry{} + dirEntryPool.Put(o) +} + +func (o DirEntry) Clone() DirEntry { + o.Data = cloneBytes(o.Data) + o.Name = cloneBytes(o.Name) + return o +} + func (o *DirEntry) UnmarshalBinary(dat []byte) (int, error) { if err := binutil.NeedNBytes(dat, 0x1e); err != nil { return 0, err @@ -49,9 +62,9 @@ func (o *DirEntry) UnmarshalBinary(dat []byte) (int, error) { if err := binutil.NeedNBytes(dat, 0x1e+int(o.DataLen)+int(o.NameLen)); err != nil { return 0, err } - o.Name = dat[n : n+int(o.NameLen)] + o.Name = cloneBytes(dat[n : n+int(o.NameLen)]) n += int(o.NameLen) - o.Data = dat[n : n+int(o.DataLen)] + o.Data = cloneBytes(dat[n : n+int(o.DataLen)]) n += int(o.DataLen) return n, nil } |