mention icon indicating copy to clipboard operation
mention copied to clipboard

Use hashmap for uniquify function

Open Longwater1234 opened this issue 7 months ago • 3 comments

Your uniquify(in []string) function in mention.go uses O(n^2) time to collect unique strings. You could switch to using map[string]struct{} for a better O(n) performance.

Longwater1234 avatar Jun 08 '25 15:06 Longwater1234

Sounds good, I don't mind accepting a PR with this improvement.

gernest avatar Jun 08 '25 15:06 gernest

Most of the time the input to uniquify() will be small. A map will be quite a lot slower. Last time I benchmarked it's not faster unless you have more than ~50 entries.

arp242 avatar Jun 08 '25 16:06 arp242

@arp242 ok. So, for the sake of future cases where the entries are many, should we switch to map? It covers both ends.

Longwater1234 avatar Jun 09 '25 10:06 Longwater1234