message: parse the IRCv3 tag block in a single pass instead of four separate split(';') scans plus an intermediate Vec for ctags

This commit is contained in:
Jean Chevronnet 2026-08-19 02:54:24 +00:00
parent 1aa02a08b9
commit fc9ae4faad

View file

@ -57,20 +57,22 @@ pub fn parse(line: &str) -> Option<Message> {
let mut concat = false; let mut concat = false;
if let Some(after_at) = rest.strip_prefix('@') { if let Some(after_at) = rest.strip_prefix('@') {
let (tags, r) = after_at.split_once(' ')?; let (tags, r) = after_at.split_once(' ')?;
ctags = tags // single pass over the tag block (was four separate split(';') scans plus an
.split(';') // intermediate Vec for ctags)
.filter(|t| t.starts_with('+')) for t in tags.split(';') {
.collect::<Vec<_>>() if t.starts_with('+') {
.join(";"); if !ctags.is_empty() {
label = tags ctags.push(';');
.split(';') }
.find_map(|t| t.strip_prefix("label=")) ctags.push_str(t);
.map(|v| v.to_string()); } else if let Some(v) = t.strip_prefix("label=") {
batch = tags label = Some(v.to_string());
.split(';') } else if let Some(v) = t.strip_prefix("batch=") {
.find_map(|t| t.strip_prefix("batch=")) batch = Some(v.to_string());
.map(|v| v.to_string()); } else if t == "draft/multiline-concat" {
concat = tags.split(';').any(|t| t == "draft/multiline-concat"); concat = true;
}
}
rest = r.trim_start_matches(' '); rest = r.trim_start_matches(' ');
} }