Skip to content

Commit b1abf33

Browse files
committed
Optimize join
1 parent f31fef8 commit b1abf33

File tree

7 files changed

+29
-49
lines changed

7 files changed

+29
-49
lines changed

libs/extractor/src/extractor/extract_global_style_from_expression.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ pub fn extract_global_style_from_expression<'a>(
2929
t.quasis
3030
.iter()
3131
.map(|q| q.value.raw.as_str())
32-
.collect::<Vec<_>>()
33-
.join("")
32+
.collect::<String>()
3433
} else {
3534
continue;
3635
};
@@ -46,8 +45,7 @@ pub fn extract_global_style_from_expression<'a>(
4645
t.quasis
4746
.iter()
4847
.map(|q| q.value.raw.as_str())
49-
.collect::<Vec<_>>()
50-
.join("")
48+
.collect::<String>()
5149
.trim()
5250
.to_string()
5351
} else {

libs/extractor/src/extractor/extract_keyframes_from_expression.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ pub fn extract_keyframes_from_expression<'a>(
2727
t.quasis
2828
.iter()
2929
.map(|q| q.value.raw.as_str())
30-
.collect::<Vec<_>>()
31-
.join("")
30+
.collect::<String>()
3231
} else if let PropertyKey::NumericLiteral(n) = &o.key {
3332
n.value.to_string()
3433
} else {

libs/extractor/src/extractor/extract_style_from_expression.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ pub fn extract_style_from_expression<'a>(
144144
&tmp.quasis
145145
.iter()
146146
.map(|q| q.value.raw.as_str())
147-
.collect::<Vec<_>>()
148-
.join(""),
147+
.collect::<String>(),
149148
level,
150149
selector,
151150
),

libs/extractor/src/utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ pub(super) fn get_number_by_literal_expression(expr: &Expression) -> Option<f64>
207207
.quasis
208208
.iter()
209209
.map(|q| q.value.raw.to_string())
210-
.collect::<Vec<String>>()
211-
.join("")
210+
.collect::<String>()
212211
.parse::<f64>()
213212
.ok(),
214213
Expression::NumericLiteral(num) => Some(num.value),

libs/extractor/src/visit.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,8 @@ impl<'a> VisitMut<'a> for DevupVisitor<'a> {
229229
.quasi
230230
.quasis
231231
.iter()
232-
.map(|quasi| quasi.value.raw.as_str())
233-
.collect::<Vec<&str>>()
234-
.join("");
232+
.map(|quasi| quasi.value.raw.to_string())
233+
.collect::<String>();
235234
match css_type.as_ref() {
236235
UtilType::Css => {
237236
let mut styles = css_to_style(&css_str, 0, &None);

libs/sheet/src/lib.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -269,21 +269,18 @@ impl StyleSheet {
269269
color_keys
270270
.into_iter()
271271
.map(|key| format!("{}:null;", convert_interface_key(&format!("${key}"))))
272-
.collect::<Vec<String>>()
273-
.join(""),
272+
.collect::<String>(),
274273
typography_interface_name,
275274
typography_keys
276275
.into_iter()
277276
.map(|key| format!("{}:null;", convert_interface_key(&key)))
278-
.collect::<Vec<String>>()
279-
.join(""),
277+
.collect::<String>(),
280278
theme_interface_name,
281279
theme_keys
282280
.into_iter()
283281
// key to pascal
284282
.map(|key| format!("{}:null;", convert_interface_key(&key)))
285-
.collect::<Vec<String>>()
286-
.join("")
283+
.collect::<String>()
287284
)
288285
}
289286
}
@@ -294,8 +291,7 @@ impl StyleSheet {
294291
.values()
295292
.flatten()
296293
.map(|import| format!("@import \"{import}\";"))
297-
.collect::<Vec<String>>()
298-
.join("");
294+
.collect::<String>();
299295
css.push_str(&self.theme.to_css());
300296

301297
for (name, map) in self.keyframes.iter() {
@@ -310,8 +306,7 @@ impl StyleSheet {
310306
.collect::<Vec<String>>()
311307
.join(";")
312308
))
313-
.collect::<Vec<String>>()
314-
.join("")
309+
.collect::<String>()
315310
));
316311
}
317312

@@ -368,8 +363,7 @@ impl StyleSheet {
368363
let inner_css = global_props
369364
.into_iter()
370365
.map(ExtractStyle::extract)
371-
.collect::<Vec<String>>()
372-
.join("");
366+
.collect::<String>();
373367
css.push_str(
374368
if let Some(break_point) = break_point {
375369
format!("@media(min-width:{break_point}px){{{inner_css}}}")
@@ -384,8 +378,7 @@ impl StyleSheet {
384378
let inner_css = sorted_props
385379
.into_iter()
386380
.map(ExtractStyle::extract)
387-
.collect::<Vec<String>>()
388-
.join("");
381+
.collect::<String>();
389382
css.push_str(
390383
if let Some(break_point) = break_point {
391384
format!("@media(min-width:{break_point}px){{{inner_css}}}")
@@ -399,8 +392,7 @@ impl StyleSheet {
399392
let inner_css = props
400393
.into_iter()
401394
.map(ExtractStyle::extract)
402-
.collect::<Vec<String>>()
403-
.join("");
395+
.collect::<String>();
404396
css.push_str(
405397
if let Some(break_point) = break_point {
406398
format!("@media(min-width:{break_point}px)and {media}{{{inner_css}}}")

libs/sheet/src/theme.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ impl Theme {
180180
Some(theme_name)
181181
};
182182
if let Some(theme_key) = theme_key {
183-
theme_declaration
184-
.push_str(format!(":root[data-theme={theme_key}]{{").as_str());
183+
theme_declaration.push_str(format!(":root[data-theme={theme_key}]{{").as_str());
185184
css_contents.push("color-scheme:dark".to_string());
186185
} else {
187186
theme_declaration.push_str(":root{".to_string().as_str());
@@ -193,10 +192,8 @@ impl Theme {
193192
let optimized_value = optimize_value(value);
194193
if theme_key.is_some() {
195194
if other_theme_key.is_none()
196-
&& let Some(default_value) = self
197-
.colors
198-
.get(&default_theme_key)
199-
.and_then(|v| {
195+
&& let Some(default_value) =
196+
self.colors.get(&default_theme_key).and_then(|v| {
200197
v.0.get(prop).and_then(|v| {
201198
if optimize_value(v) == optimized_value {
202199
None
@@ -209,21 +206,18 @@ impl Theme {
209206
css_color_contents.push(format!("--{prop}:{default_value}"));
210207
}
211208
} else {
212-
let other_theme_value = other_theme_key
213-
.as_ref()
214-
.and_then(|other_theme_key| {
215-
self.colors
216-
.get(other_theme_key)
217-
.and_then(|v| {
218-
v.0.get(prop).and_then(|v| {
219-
let other_theme_value = optimize_value(v.as_str());
220-
if other_theme_value == optimized_value {
221-
None
222-
} else {
223-
Some(other_theme_value)
224-
}
225-
})
209+
let other_theme_value =
210+
other_theme_key.as_ref().and_then(|other_theme_key| {
211+
self.colors.get(other_theme_key).and_then(|v| {
212+
v.0.get(prop).and_then(|v| {
213+
let other_theme_value = optimize_value(v.as_str());
214+
if other_theme_value == optimized_value {
215+
None
216+
} else {
217+
Some(other_theme_value)
218+
}
226219
})
220+
})
227221
});
228222
// default theme
229223
css_color_contents.push(format!(

0 commit comments

Comments
 (0)