Skip to content

Commit

Permalink
perf: optimize trie construction (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored Sep 7, 2024
1 parent c0dad1d commit 9954aef
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/database/customEmojiIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ export function customEmojiIndex (customEmojis) {
//
// search()
//
const emojiToTokens = emoji => (
[...new Set((emoji.shortcodes || []).map(shortcode => extractTokens(shortcode)).flat())]
)
const emojiToTokens = emoji => {
const set = new Set()
if (emoji.shortcodes) {
for (const shortcode of emoji.shortcodes) {
for (const token of extractTokens(shortcode)) {
set.add(token)
}
}
}
return set
}
const searchTrie = trie(customEmojis, emojiToTokens)
const searchByExactMatch = _ => searchTrie(_, true)
const searchByPrefix = _ => searchTrie(_, false)
Expand Down

0 comments on commit 9954aef

Please sign in to comment.