perf(ui/chat): add fast-path mention expansion (#689)

This commit is contained in:
Ayyan 2026-01-05 04:29:36 -05:00 • committed by GitHub
parent 2c2afe3b09
commit 3322bc2892
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -39,7 +39,7 @@ var mentionRegex = regexp.MustCompile("@[a-zA-Z0-9._]+")
type messageInput struct {
*tview.TextArea
cfg *config.Config
cfg *config.Config
chatView *View
edit bool
@ -53,7 +53,7 @@ func newMessageInput(cfg *config.Config, chatView *View) *messageInput {
mi := &messageInput{
TextArea: tview.NewTextArea(),
cfg: cfg,
chatView: chatView,
chatView: chatView,
sendMessageData: &api.SendMessageData{},
cache: cache.NewCache(),
mentionsList: tview.NewList(),
@ -198,6 +198,16 @@ func (mi *messageInput) send() {
}
func processText(state *ningen.State, channel *discord.Channel, src []byte) string {
// Fast path: no mentions to expand.
if bytes.IndexByte(src, '@') == -1 {
return string(src)
}
// Fast path: no back ticks (code blocks), so expand mentions directly.
if bytes.IndexByte(src, '`') == -1 {
return string(expandMentions(state, channel, src))
}
var (
ranges [][2]int
canMention = true