tamer: Intern desc from xmle on read
The new xmle writer was having to intern before write, which did not make sense. This continues with consistently using symbols throughout the system, and is a smaller size than `String` as a bonus.main
parent
5250571f15
commit
acf55fad81
|
@ -520,7 +520,7 @@ mod test {
|
|||
syma,
|
||||
IdentKind::Meta,
|
||||
Source {
|
||||
desc: Some("a".to_string()),
|
||||
desc: Some("a".into()),
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
|
@ -529,7 +529,7 @@ mod test {
|
|||
symb,
|
||||
IdentKind::Worksheet,
|
||||
Source {
|
||||
desc: Some("b".to_string()),
|
||||
desc: Some("b".into()),
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
|
@ -541,7 +541,7 @@ mod test {
|
|||
Some((
|
||||
IdentKind::Meta,
|
||||
Source {
|
||||
desc: Some("a".to_string()),
|
||||
desc: Some("a".into()),
|
||||
..Default::default()
|
||||
},
|
||||
)),
|
||||
|
@ -553,7 +553,7 @@ mod test {
|
|||
Some((
|
||||
IdentKind::Worksheet,
|
||||
Source {
|
||||
desc: Some("b".to_string()),
|
||||
desc: Some("b".into()),
|
||||
..Default::default()
|
||||
},
|
||||
)),
|
||||
|
@ -567,7 +567,7 @@ mod test {
|
|||
fn lookup_by_symbol() -> AsgResult<()> {
|
||||
let mut sut = Sut::new();
|
||||
|
||||
let sym = "lookup".intern();
|
||||
let sym = "lookup".into();
|
||||
let node = sut.declare(
|
||||
sym,
|
||||
IdentKind::Meta,
|
||||
|
@ -586,7 +586,7 @@ mod test {
|
|||
fn declare_returns_existing() -> AsgResult<()> {
|
||||
let mut sut = Sut::new();
|
||||
|
||||
let sym = "symdup".intern();
|
||||
let sym = "symdup".into();
|
||||
let src = Source::default();
|
||||
let node = sut.declare(sym, IdentKind::Meta, src.clone())?;
|
||||
|
||||
|
|
|
@ -635,7 +635,7 @@ pub struct Source {
|
|||
///
|
||||
/// This is used primarily by [`IdentKind::Class`] and
|
||||
/// [`IdentKind::Gen`].
|
||||
pub desc: Option<String>,
|
||||
pub desc: Option<SymbolId>,
|
||||
|
||||
/// Whether this identifier was generated by the compiler.
|
||||
///
|
||||
|
@ -1664,7 +1664,7 @@ mod test {
|
|||
generated: true,
|
||||
parent: Some(psym),
|
||||
yields: Some(ysym),
|
||||
desc: Some("sym desc".to_string()),
|
||||
desc: Some("sym desc".into()),
|
||||
from: Some(vec![fsym]),
|
||||
virtual_: true,
|
||||
override_: true,
|
||||
|
@ -1678,7 +1678,7 @@ mod test {
|
|||
generated: attrs.generated,
|
||||
parent: attrs.parent,
|
||||
yields: attrs.yields,
|
||||
desc: Some("sym desc".to_string()),
|
||||
desc: Some("sym desc".into()),
|
||||
from: Some(vec![fsym]),
|
||||
virtual_: true,
|
||||
override_: true,
|
||||
|
|
|
@ -149,7 +149,7 @@ pub struct SymAttrs {
|
|||
/// User-friendly identifier description.
|
||||
///
|
||||
/// This is used primarily by [`SymType::Class`] and [`SymType::Gen`].
|
||||
pub desc: Option<String>,
|
||||
pub desc: Option<SymbolId>,
|
||||
|
||||
/// Related identifiers.
|
||||
///
|
||||
|
|
|
@ -276,7 +276,7 @@ impl<W: Write> XmleWriter<W> {
|
|||
attrs.push(("yields", yields));
|
||||
}
|
||||
if let Some(desc) = &src.desc {
|
||||
attrs.push(("desc", &desc));
|
||||
attrs.push(("desc", desc.lookup_str().as_str()));
|
||||
}
|
||||
|
||||
let sym = BytesStart::owned_name(b"preproc:sym".to_vec())
|
||||
|
@ -649,7 +649,7 @@ mod test {
|
|||
generated: true,
|
||||
parent: Some(psym),
|
||||
yields: Some(ysym),
|
||||
desc: Some("sym desc".to_string()),
|
||||
desc: Some("sym desc".into()),
|
||||
from: Some(vec![fsym]),
|
||||
virtual_: true,
|
||||
..Default::default()
|
||||
|
|
|
@ -25,7 +25,7 @@ use crate::{
|
|||
xir::{AttrValue, QName, Token},
|
||||
},
|
||||
ld::LSPAN,
|
||||
sym::{st::*, GlobalSymbolIntern, SymbolId},
|
||||
sym::{st::*, SymbolId},
|
||||
};
|
||||
use arrayvec::ArrayVec;
|
||||
use std::array;
|
||||
|
@ -121,12 +121,7 @@ impl<'a, T: IdentObjectData> DepListIter<'a, T> {
|
|||
false => None,
|
||||
});
|
||||
|
||||
// TODO: interning ought to be done during read, not by us
|
||||
self.toks_push_attr(
|
||||
QN_DESC,
|
||||
src.desc.as_ref().map(|s| GlobalSymbolIntern::clone_uninterned(s.as_ref()))
|
||||
);
|
||||
|
||||
self.toks_push_attr(QN_DESC, src.desc);
|
||||
self.toks_push_attr(QN_YIELDS, src.yields);
|
||||
self.toks_push_attr(QN_PARENT, src.parent);
|
||||
self.toks_push_attr(QN_NAME, Some(sym));
|
||||
|
@ -221,7 +216,7 @@ pub mod test {
|
|||
tree::{parser_from, Attr},
|
||||
},
|
||||
};
|
||||
use crate::sym::GlobalSymbolResolve;
|
||||
use crate::sym::{GlobalSymbolIntern, GlobalSymbolResolve};
|
||||
|
||||
type TestResult = Result<(), Box<dyn std::error::Error>>;
|
||||
|
||||
|
@ -265,7 +260,7 @@ pub mod test {
|
|||
"a".intern(),
|
||||
IdentKind::Meta,
|
||||
Source {
|
||||
desc: Some(String::from("test desc")),
|
||||
desc: Some("test desc".intern()),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
|
@ -381,7 +376,7 @@ pub mod test {
|
|||
.and_then(|a| a.value_atom())
|
||||
{
|
||||
Some(AttrValue::Escaped(given)) => {
|
||||
assert_eq!(desc, &given.lookup_str() as &str);
|
||||
assert_eq!(desc.lookup_str(), given.lookup_str());
|
||||
}
|
||||
invalid => panic!("unexpected desc: {:?}", invalid),
|
||||
}
|
||||
|
|
|
@ -464,9 +464,8 @@ where
|
|||
}
|
||||
|
||||
b"desc" => {
|
||||
sym_attrs.desc = Some(unsafe {
|
||||
String::from_utf8_unchecked(attr.value.to_vec())
|
||||
});
|
||||
sym_attrs.desc =
|
||||
Some(unsafe { attr.value.intern_utf8_unchecked() });
|
||||
}
|
||||
|
||||
b"virtual" => {
|
||||
|
|
|
@ -770,7 +770,7 @@ sym_tests! {
|
|||
}
|
||||
|
||||
desc: [desc="Description"] => SymAttrs {
|
||||
desc: Some("Description".to_string()),
|
||||
desc: Some("Description".into()),
|
||||
..Default::default()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue