Ad
  • Default User Avatar

    Or maybe we can pre-allocate the result, so when we do append, go will not change slice header since we allocate it as the size of str input.
    result := make([]rune, 0, len(str)

  • Custom User Avatar

    With append you're actually allocating a new array underneath with it's size increased by the ammount of items added. In this case the size of the resulting value is already known so it would be more efficient to allocate a slice of rune with predefined length ( length of the string provided ) and assign the values directly.

  • Default User Avatar