Reduce segment cloning when rendering messages (#33340)

While working on retries, I discovered some opportunities to reduce
cloning of message segments. These segments have full `String`s (not
`SharedString`s), so cloning them means copying cloning all the bytes of
all the strings in the message, which would be nice to avoid!

Release Notes:

- N/A
This commit is contained in:
Richard Feldman 2025-06-25 14:10:48 -04:00 committed by GitHub
parent 8e831ced5b
commit 4516b099e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 98 additions and 86 deletions

View file

@ -198,6 +198,13 @@ impl MessageSegment {
Self::RedactedThinking(_) => false,
}
}
pub fn text(&self) -> Option<&str> {
match self {
MessageSegment::Text(text) => Some(text),
_ => None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]