From acbbfafa07922b458506b91a58f3a082da453fd1 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 11 Feb 2023 22:33:44 -0700 Subject: Try to avoid unnecessary allocations in enum-types' String methods --- lib/btrfs/Makefile | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'lib/btrfs/Makefile') 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 -- cgit v1.2.3-2-g168b