summaryrefslogtreecommitdiffhomepage
path: root/pkg/abi
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2018-12-06 11:42:23 -0800
committerShentubot <shentubot@google.com>2018-12-06 11:43:11 -0800
commit666db00c262c7d6d6359fbaba28e344d015a7823 (patch)
treebe5e9ca85570c04ec5625b79657ab47b0a38aada /pkg/abi
parent000fa84a3bb1aebeda235c56545c942d7c29003d (diff)
Convert ValueSet to a map
Unlike FlagSet, order doesn't matter here, so it can simply be a map. PiperOrigin-RevId: 224377910 Change-Id: I15810c698a7f02d8614bf09b59583ab73cba0514
Diffstat (limited to 'pkg/abi')
-rw-r--r--pkg/abi/flag.go25
-rw-r--r--pkg/abi/linux/file.go35
2 files changed, 17 insertions, 43 deletions
diff --git a/pkg/abi/flag.go b/pkg/abi/flag.go
index 0698e410f..049c1b0dd 100644
--- a/pkg/abi/flag.go
+++ b/pkg/abi/flag.go
@@ -46,30 +46,25 @@ func (s FlagSet) Parse(val uint64) string {
return strings.Join(flags, "|")
}
-// ValueSet is a slice of syscall values and their name. Parse will replace
-// values that exactly match an entry with its name.
-type ValueSet []struct {
- Value uint64
- Name string
-}
+// ValueSet is a map of syscall values to their name. Parse will use the name
+// or the value if unknown.
+type ValueSet map[uint64]string
// Parse returns the name of the value associated with `val`. Unknown values
// are converted to hex.
-func (e ValueSet) Parse(val uint64) string {
- for _, f := range e {
- if val == f.Value {
- return f.Name
- }
+func (s ValueSet) Parse(val uint64) string {
+ if v, ok := s[val]; ok {
+ return v
}
return fmt.Sprintf("%#x", val)
}
// ParseName returns the flag value associated with 'name'. Returns false
// if no value is found.
-func (e ValueSet) ParseName(name string) (uint64, bool) {
- for _, f := range e {
- if name == f.Name {
- return f.Value, true
+func (s ValueSet) ParseName(name string) (uint64, bool) {
+ for k, v := range s {
+ if v == name {
+ return k, true
}
}
return math.MaxUint64, false
diff --git a/pkg/abi/linux/file.go b/pkg/abi/linux/file.go
index 8d48e1753..ac49ae9a6 100644
--- a/pkg/abi/linux/file.go
+++ b/pkg/abi/linux/file.go
@@ -223,32 +223,11 @@ var modeExtraBits = abi.FlagSet{
}
var fileType = abi.ValueSet{
- {
- Value: ModeSocket,
- Name: "S_IFSOCK",
- },
- {
- Value: ModeSymlink,
- Name: "S_IFLINK",
- },
- {
- Value: ModeRegular,
- Name: "S_IFREG",
- },
- {
- Value: ModeBlockDevice,
- Name: "S_IFBLK",
- },
- {
- Value: ModeDirectory,
- Name: "S_IFDIR",
- },
- {
- Value: ModeCharacterDevice,
- Name: "S_IFCHR",
- },
- {
- Value: ModeNamedPipe,
- Name: "S_IFIFO",
- },
+ ModeSocket: "S_IFSOCK",
+ ModeSymlink: "S_IFLINK",
+ ModeRegular: "S_IFREG",
+ ModeBlockDevice: "S_IFBLK",
+ ModeDirectory: "S_IFDIR",
+ ModeCharacterDevice: "S_IFCHR",
+ ModeNamedPipe: "S_IFIFO",
}