chiark / gitweb /
html, SvgAttrs: Change type of SvgAttrs
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 1 Apr 2021 10:57:47 +0000 (11:57 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 1 Apr 2021 10:57:47 +0000 (11:57 +0100)
Amazingly this seems to *save* 2k of wasm code.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
base/html.rs
base/misc.rs
daemon/session.rs

index 20f3b13061c1720e1a69f6c838a17996dc07b7df..caff21c7124e4b146e453ca7e303d611d0060b66 100644 (file)
@@ -48,6 +48,8 @@ impl Debug for Html {
 pub struct HtmlStr(str);
 
 #[derive(Hash,Eq,Ord,PartialEq,PartialOrd)]
+#[derive(Serialize,Deserialize)]
+#[serde(transparent)]
 pub struct HtmlLit(&'static str);
 
 impl From<HtmlLit> for &'static HtmlStr {
index 963dc67602cf08e0ae22362a9f677e04e5a9190d..426c4ca9a8d1401d03d166383f536bfb98c07628 100644 (file)
@@ -47,20 +47,20 @@ macro_rules! display_as_debug {
 }
 pub use crate::display_as_debug;
 
-pub type SvgAttrs = Vec<(String,String)>;
+pub type SvgAttrs = Vec<(HtmlLit,Html)>;
 
 pub fn space_table_attrs(table_size: PosC<f64>) -> SvgAttrs {
   let PosC { coords: [x, y] } = table_size.into();
   vec![
-    ("viewBox".to_owned(), format!("0 0 {x} {y}", x=x, y=y) ),
-    ("width"  .to_owned(), (SVG_SCALE * x).to_string()  ),
-    ("height" .to_owned(), (SVG_SCALE * y).to_string()  ),
+    (Html::lit("viewBox"), hformat!("0 0 {} {}", x, y) ),
+    (Html::lit("width"  ), (SVG_SCALE * x).to_html()  ),
+    (Html::lit("height" ), (SVG_SCALE * y).to_html()  ),
   ]
 }
 
 pub fn space_rect_attrs(table_size: PosC<f64>) -> SvgAttrs {
   vec![
-    ("width"  .to_owned(), table_size.x().to_string()  ),
-    ("height" .to_owned(), table_size.y().to_string()  ),
+    (Html::lit("width" ), table_size.x().to_html()  ),
+    (Html::lit("height"), table_size.y().to_html()  ),
   ]
 }
index 4076a5bebcc3718161b5622b916b4cc5f9e9693c..14444f790d7ec1804d4cdc541087462f9efa9194 100644 (file)
@@ -74,11 +74,11 @@ fn session(form: Json<SessionForm>,
 #[ext]
 impl SvgAttrs {
   fn to_html(&self) -> Html {
-    let mut o = String::new();
+    let mut o = Html::new();
     for (k,v) in self {
-      write!(o, r##"{}="{}""##, k, v).unwrap();
+      hwrite!(&mut o, r##"{}="{}""##, k, v).unwrap();
     }
-    Html::from_html_string(o)
+    o
   }
 }