Просмотр исходного кода

refactor: migrate bool to empty struct for lower memory usage

Andrey Nering 6 месяцев назад
Родитель
Сommit
9eb207f3cf
1 измененных файлов с 4 добавлено и 3 удалено
  1. 4 3
      internal/shell/shell.go

+ 4 - 3
internal/shell/shell.go

@@ -157,16 +157,17 @@ func (s *Shell) SetBlockFuncs(blockFuncs []BlockFunc) {
 
 // CommandsBlocker creates a BlockFunc that blocks exact command matches
 func CommandsBlocker(bannedCommands []string) BlockFunc {
-	bannedSet := make(map[string]bool)
+	bannedSet := make(map[string]struct{})
 	for _, cmd := range bannedCommands {
-		bannedSet[cmd] = true
+		bannedSet[cmd] = struct{}{}
 	}
 
 	return func(args []string) bool {
 		if len(args) == 0 {
 			return false
 		}
-		return bannedSet[args[0]]
+		_, ok := bannedSet[args[0]]
+		return ok
 	}
 }