summaryrefslogtreecommitdiff
path: root/lib/btrfs/Makefile
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-11 22:33:44 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-12 16:17:27 -0700
commitacbbfafa07922b458506b91a58f3a082da453fd1 (patch)
tree020cb033adb3809bcc8ffed5f56ba8d167b32dd1 /lib/btrfs/Makefile
parent1f3a1a474ac41f427e4c5b0d27d2c85a3cfaa65e (diff)
Try to avoid unnecessary allocations in enum-types' String methods
Diffstat (limited to 'lib/btrfs/Makefile')
-rw-r--r--lib/btrfs/Makefile9
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/btrfs/Makefile b/lib/btrfs/Makefile
index 015c3e1..b98a1b7 100644
--- a/lib/btrfs/Makefile
+++ b/lib/btrfs/Makefile
@@ -80,13 +80,10 @@ btrfsprim/itemtype.go: btrfsitem/items.txt $(MAKEFILE_LIST)
sed -E 's,(.*)=([^:]*)(:.*)? (trivial|complex) (.*),\1_KEY ItemType=\2,' $< | uniq; \
echo ')'; \
echo 'func (t ItemType) String() string {'; \
- echo ' names := map[ItemType]string{'; \
- sed -E 's@(.*)=(.*) (trivial|complex) (.*)@\1_KEY: "\1",@' $< | sed 's/"UUID_/&KEY_/'; \
+ echo ' switch t {'; \
+ sed -E 's@(.*)=(.*) (trivial|complex) (.*)@case \1_KEY: return "\1"@' $< | sed 's/"UUID_/&KEY_/'; \
+ echo ' default: return fmt.Sprintf("%d", t)'; \
echo ' }'; \
- echo ' if name, ok := names[t]; ok {'; \
- echo ' return name'; \
- echo ' }'; \
- echo ' return fmt.Sprintf("%d", t)'; \
echo '}'; \
} | gofmt >$@
files += btrfsprim/itemtype.go