Skip to content

fix: C macro memory issue #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

## [unreleased]
- [BREAKING] Rename `linear_gradient!` to `linearGradient!` for consistency with the other svg macros (same with `radial_gradient!` and `mesh_gradient!`).
- [BREAKING] Rename `linear_gradient!` to `linearGradient!` for consistency with the other svg macros (same with `radial_gradient!` and `mesh_gradient!`) (#377).
- Fixed `base_path` with a trailing slash parsing / handling.
- Fixed `C` macro memory / WASM file size issue.

## v0.7.0
- [BREAKING] Custom elements are now patched in-place (#364). Use `el_key` to force reinitialize an element.
Expand Down
35 changes: 23 additions & 12 deletions src/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// @TODO merge with `pub use` & `prelude` in `lib.rs` and `browser::util`?

use crate::virtual_dom::{At, Attrs};
use wasm_bindgen::JsValue;

/// Copied from [https://github.com/rust-lang/rust/issues/35853](https://github.com/rust-lang/rust/issues/35853)
Expand Down Expand Up @@ -325,22 +326,32 @@ macro_rules! C {
{
let mut all_classes = Vec::new();
$(
if let Some(classes) = $class.to_classes() {
for class in classes {
if !class.is_empty() {
all_classes.push(class);
}
}
}
$crate::shortcuts::_fill_all_classes(&mut all_classes, $class.to_classes());
)*
$crate::shortcuts::_all_classes_to_attrs(&all_classes)
}
};
}

let mut attrs = $crate::virtual_dom::Attrs::empty();
if !all_classes.is_empty() {
attrs.add_multiple(At::Class, &all_classes.iter().map(|class| class.as_str()).collect::<Vec<_>>());
pub fn _fill_all_classes(all_classes: &mut Vec<String>, classes: Option<Vec<String>>) {
if let Some(classes) = classes {
for class in classes {
if !class.is_empty() {
all_classes.push(class);
}
attrs
}
};
}
}

pub fn _all_classes_to_attrs(all_classes: &[String]) -> Attrs {
let mut attrs = Attrs::empty();
if !all_classes.is_empty() {
attrs.add_multiple(
At::Class,
&all_classes.iter().map(String::as_str).collect::<Vec<_>>(),
);
}
attrs
}

/// `IF!(predicate => expression) -> Option<expression value>`
Expand Down