Skip to content

Commit

Permalink
Use strings.EqualFold in case-insensitive comparisons (#479)
Browse files Browse the repository at this point in the history
`strings.EqualFold` is simpler and much faster than `strings.ToLower`.
  • Loading branch information
apocelipes committed Jun 10, 2024
1 parent 84f2270 commit bc111c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,27 +792,27 @@ func fileSummarize(input chan *FileJob) string {
}

switch {
case More || strings.ToLower(Format) == "wide":
case More || strings.EqualFold(Format, "wide"):
return fileSummarizeLong(input)
case strings.ToLower(Format) == "json":
case strings.EqualFold(Format, "json"):
return toJSON(input)
case strings.ToLower(Format) == "json2":
case strings.EqualFold(Format, "json2"):
return toJSON2(input)
case strings.ToLower(Format) == "cloc-yaml" || strings.ToLower(Format) == "cloc-yml":
case strings.EqualFold(Format, "cloc-yaml") || strings.EqualFold(Format, "cloc-yml"):
return toClocYAML(input)
case strings.ToLower(Format) == "csv":
case strings.EqualFold(Format, "csv"):
return toCSV(input)
case strings.ToLower(Format) == "csv-stream":
case strings.EqualFold(Format, "csv-stream"):
return toCSVStream(input)
case strings.ToLower(Format) == "html":
case strings.EqualFold(Format, "html"):
return toHtml(input)
case strings.ToLower(Format) == "html-table":
case strings.EqualFold(Format, "html-table"):
return toHtmlTable(input)
case strings.ToLower(Format) == "sql":
case strings.EqualFold(Format, "sql"):
return toSql(input)
case strings.ToLower(Format) == "sql-insert":
case strings.EqualFold(Format, "sql-insert"):
return toSqlInsert(input)
case strings.ToLower(Format) == "openmetrics":
case strings.EqualFold(Format, "openmetrics"):
return toOpenMetrics(input)
}

Expand Down Expand Up @@ -1421,7 +1421,7 @@ func calculateSize(sumBytes int64, str *strings.Builder) {
SizeUnit = "SI"
}

if strings.ToLower(SizeUnit) != "xkcd-imaginary" {
if !strings.EqualFold(SizeUnit, "xkcd-imaginary") {
str.WriteString(fmt.Sprintf("Processed %d bytes, %.3f megabytes (%s)\n", sumBytes, size, strings.ToUpper(SizeUnit)))
}
}
Expand Down
2 changes: 1 addition & 1 deletion processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func setupCountAs() {
// See if we can identify based on language name which is the most
// reliable as the name should be unique
for name := range languageDatabase {
if strings.ToLower(name) == strings.ToLower(t[1]) {
if strings.EqualFold(name, t[1]) {
ExtensionToLanguage[strings.ToLower(t[0])] = []string{name}
identified = true
if Debug {
Expand Down

0 comments on commit bc111c9

Please sign in to comment.