rivo / uniseg

Unicode Text Segmentation, Word Wrapping, and String Width Calculation in Go
MIT License
585 stars 61 forks source link

add NewGraphemesFromRunes #20

Closed charlievieth closed 1 year ago

charlievieth commented 2 years ago

Add NewGraphemesFromRunes which allows for creating a new Graphemes struct from a slice of runes (saving the []rune => str => []rune conversion).

rivo commented 2 years ago

Do you have an actual use case in your application where you work with slices of runes?

dchapes commented 2 years ago

@charlievieth the way to avoid the conversions is to re-write the code in this package to not use []rune internally. Doing so speeds up common operations and only has slight slowdowns for less common operations.

I can only guess you're suggesting this API because you have some code with []rune already; a lot of the Go code I see using []rune shouldn't be so I'd also suggest reviewing said code and making sure it really benefits from []rune (often for an extremely minor increase in code complexity []rune conversions can be removed entirely and the resulting code runs faster by avoiding conversions; especially as the input size increases).

rivo commented 1 year ago

I believe this PR also doesn't apply anymore after the rewrite last year.