1
0
Fork 0
forked from wry/wry

wayland: optimize parsing of fixed-size messages

This commit is contained in:
Julian Orth 2026-03-28 22:07:41 +01:00
parent b745e20f7f
commit 755bfdd661
6 changed files with 92 additions and 25 deletions

View file

@ -427,7 +427,6 @@ impl Client {
mut parser: MsgParser<'_, 'a>,
) -> Result<R, MsgParserError> {
let res = R::parse(&mut parser)?;
parser.eof()?;
log::trace!(
"Client {} -> {}@{}.{:?}",
self.id,

View file

@ -146,9 +146,7 @@ pub trait ParseFull<'a>: Sized {
impl<'a, T: RequestParser<'a>> ParseFull<'a> for T {
fn parse_full(mut parser: MsgParser<'_, 'a>) -> Result<Self, TestError> {
let res = T::parse(&mut parser)?;
parser.eof()?;
Ok(res)
T::parse(&mut parser).map_err(Into::into)
}
}

View file

@ -22,6 +22,8 @@ pub enum MsgParserError {
TrailingData,
#[error("String is not UTF-8")]
NonUtf8,
#[error("The message has an unexpected size")]
UnexpectedMessageSize,
}
pub struct MsgParser<'a, 'b> {
@ -35,6 +37,11 @@ impl<'a, 'b> MsgParser<'a, 'b> {
Self { buf, pos: 0, data }
}
#[inline(always)]
pub fn data(&self) -> &[u32] {
self.data
}
pub fn int(&mut self) -> Result<i32, MsgParserError> {
if self.pos >= self.data.len() {
return Err(MsgParserError::UnexpectedEof);
@ -48,12 +55,14 @@ impl<'a, 'b> MsgParser<'a, 'b> {
self.int().map(|i| i as u32)
}
#[expect(dead_code)]
pub fn u64(&mut self) -> Result<u64, MsgParserError> {
let hi = self.uint()?;
let lo = self.uint()?;
Ok(((hi as u64) << 32) | lo as u64)
}
#[expect(dead_code)]
pub fn u64_rev(&mut self) -> Result<u64, MsgParserError> {
let lo = self.uint()?;
let hi = self.uint()?;

View file

@ -257,7 +257,6 @@ impl UsrCon {
mut parser: MsgParser<'_, 'a>,
) -> Result<R, MsgParserError> {
let res = R::parse(&mut parser)?;
parser.eof()?;
log::trace!(
"Server {} -> {}@{}.{:?}",
self.server_id,