perf(css/codegen): Skip useless operations if not required (#5802)

**Description:**

The column is used only for sourcemap, so we can skip `chars().count()` if we are not generating source maps.
This commit is contained in:
Donny/강동윤 2022-09-10 15:36:15 +09:00 committed by GitHub
parent 4c078b0ac3
commit b96eb1ead8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,7 +113,9 @@ where
fn raw_write(&mut self, data: &str) -> Result {
self.w.write_str(data)?;
self.col += data.chars().count();
if self.srcmap.is_some() {
self.col += data.chars().count();
}
Ok(())
}
@ -216,11 +218,15 @@ where
let line_start_of_s = compute_line_starts(s);
if line_start_of_s.len() > 1 {
self.line = self.line + line_start_of_s.len() - 1;
if self.srcmap.is_some() {
self.line = self.line + line_start_of_s.len() - 1;
}
let last_line_byte_index = line_start_of_s.last().cloned().unwrap_or(0);
self.col = s[last_line_byte_index..].chars().count();
if self.srcmap.is_some() {
self.col = s[last_line_byte_index..].chars().count();
}
}
if !span.is_dummy() {