Go

Go

Made by DeepSource

Use utf8.DecodeRuneInString instead of []rune(string)[0] GO-P4006

Performance
Major

It is recommended to use utf8.DecodeRuneInString instead of []rune(string)[0] to prevent unwanted rune slice allocation.

Bad practice

package main

func getFirstRune(s string) rune {
  r := []rune(s)[0]
  return r
}

Recommended

package main

import (
  "unicode/utf8"
)

func getFirstRune(s string) rune {
  r, _ := utf8.DecodeRuneInString(s)
  return r
}