Reduce Result<Tok, LexicalError> size by using Box<str> instead of String (#9885)

This commit is contained in:
Micha Reiser 2024-02-08 21:36:22 +01:00 committed by GitHub
parent 9027169125
commit fe7d965334
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 454 additions and 425 deletions

View file

@ -16,7 +16,7 @@ pub enum Tok {
/// Token value for a name, commonly known as an identifier.
Name {
/// The name value.
name: String,
name: Box<str>,
},
/// Token value for an integer.
Int {
@ -38,7 +38,7 @@ pub enum Tok {
/// Token value for a string.
String {
/// The string value.
value: String,
value: Box<str>,
/// The kind of string.
kind: StringKind,
/// Whether the string is triple quoted.
@ -51,7 +51,7 @@ pub enum Tok {
/// part of the expression part and isn't an opening or closing brace.
FStringMiddle {
/// The string value.
value: String,
value: Box<str>,
/// Whether the string is raw or not.
is_raw: bool,
/// Whether the string is triple quoted.
@ -63,12 +63,12 @@ pub enum Tok {
/// only when the mode is [`Mode::Ipython`].
IpyEscapeCommand {
/// The magic command value.
value: String,
value: Box<str>,
/// The kind of magic command.
kind: IpyEscapeKind,
},
/// Token value for a comment. These are filtered out of the token stream prior to parsing.
Comment(String),
Comment(Box<str>),
/// Token value for a newline.
Newline,
/// Token value for a newline that is not a logical line break. These are filtered out of
@ -912,3 +912,14 @@ impl From<&Tok> for TokenKind {
Self::from_token(value)
}
}
#[cfg(target_pointer_width = "64")]
mod sizes {
use crate::lexer::{LexicalError, LexicalErrorType};
use crate::Tok;
use static_assertions::assert_eq_size;
assert_eq_size!(Tok, [u8; 24]);
assert_eq_size!(LexicalErrorType, [u8; 24]);
assert_eq_size!(Result<Tok, LexicalError>, [u8; 32]);
}