Don't do profile timing on wasm32

This commit is contained in:
Audrey Dutcher 2023-01-23 10:57:06 -07:00 committed by Jeremy Soller
parent 1225106ddc
commit a5903bb3bf
2 changed files with 18 additions and 10 deletions

View file

@ -319,7 +319,7 @@ impl<'a> Buffer<'a> {
} }
fn relayout(&mut self) { fn relayout(&mut self) {
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_arch = "wasm32")))]
let instant = std::time::Instant::now(); let instant = std::time::Instant::now();
for line in &mut self.lines { for line in &mut self.lines {
@ -336,13 +336,13 @@ impl<'a> Buffer<'a> {
self.redraw = true; self.redraw = true;
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_arch = "wasm32")))]
log::debug!("relayout: {:?}", instant.elapsed()); log::debug!("relayout: {:?}", instant.elapsed());
} }
/// Pre-shape lines in the buffer, up to `lines`, return actual number of layout lines /// Pre-shape lines in the buffer, up to `lines`, return actual number of layout lines
pub fn shape_until(&mut self, lines: i32) -> i32 { pub fn shape_until(&mut self, lines: i32) -> i32 {
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_arch = "wasm32")))]
let instant = std::time::Instant::now(); let instant = std::time::Instant::now();
let mut reshaped = 0; let mut reshaped = 0;
@ -365,7 +365,7 @@ impl<'a> Buffer<'a> {
} }
if reshaped > 0 { if reshaped > 0 {
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_arch = "wasm32")))]
log::debug!("shape_until {}: {:?}", reshaped, instant.elapsed()); log::debug!("shape_until {}: {:?}", reshaped, instant.elapsed());
self.redraw = true; self.redraw = true;
} }
@ -375,7 +375,7 @@ impl<'a> Buffer<'a> {
/// Shape lines until cursor, also scrolling to include cursor in view /// Shape lines until cursor, also scrolling to include cursor in view
pub fn shape_until_cursor(&mut self, cursor: Cursor) { pub fn shape_until_cursor(&mut self, cursor: Cursor) {
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_arch = "wasm32")))]
let instant = std::time::Instant::now(); let instant = std::time::Instant::now();
let mut reshaped = 0; let mut reshaped = 0;
@ -404,7 +404,7 @@ impl<'a> Buffer<'a> {
} }
if reshaped > 0 { if reshaped > 0 {
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_arch = "wasm32")))]
log::debug!("shape_until_cursor {}: {:?}", reshaped, instant.elapsed()); log::debug!("shape_until_cursor {}: {:?}", reshaped, instant.elapsed());
self.redraw = true; self.redraw = true;
} }
@ -577,7 +577,7 @@ impl<'a> Buffer<'a> {
/// Convert x, y position to Cursor (hit detection) /// Convert x, y position to Cursor (hit detection)
pub fn hit(&self, x: i32, y: i32) -> Option<Cursor> { pub fn hit(&self, x: i32, y: i32) -> Option<Cursor> {
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_arch = "wasm32")))]
let instant = std::time::Instant::now(); let instant = std::time::Instant::now();
let font_size = self.metrics.font_size; let font_size = self.metrics.font_size;
@ -670,7 +670,7 @@ impl<'a> Buffer<'a> {
} }
} }
#[cfg(feature = "std")] #[cfg(all(feature = "std", not(target_arch = "wasm32")))]
log::trace!("click({}, {}): {:?}", x, y, instant.elapsed()); log::trace!("click({}, {}): {:?}", x, y, instant.elapsed());
new_cursor_opt new_cursor_opt

View file

@ -33,6 +33,7 @@ impl FontSystem {
let mut db = fontdb::Database::new(); let mut db = fontdb::Database::new();
{ {
#[cfg(not(target_arch = "wasm32"))]
let now = std::time::Instant::now(); let now = std::time::Instant::now();
db.load_system_fonts(); db.load_system_fonts();
@ -41,6 +42,7 @@ impl FontSystem {
db.set_sans_serif_family("Fira Sans"); db.set_sans_serif_family("Fira Sans");
db.set_serif_family("DejaVu Serif"); db.set_serif_family("DejaVu Serif");
#[cfg(not(target_arch = "wasm32"))]
log::info!( log::info!(
"Parsed {} font faces in {}ms.", "Parsed {} font faces in {}ms.",
db.len(), db.len(),
@ -54,6 +56,7 @@ impl FontSystem {
/// Create a new [`FontSystem`], manually specifying the current locale and font database. /// Create a new [`FontSystem`], manually specifying the current locale and font database.
pub fn new_with_locale_and_db(locale: String, mut db: fontdb::Database) -> Self { pub fn new_with_locale_and_db(locale: String, mut db: fontdb::Database) -> Self {
{ {
#[cfg(not(target_arch = "wasm32"))]
let now = std::time::Instant::now(); let now = std::time::Instant::now();
//TODO only do this on demand! //TODO only do this on demand!
@ -64,6 +67,7 @@ impl FontSystem {
} }
} }
#[cfg(not(target_arch = "wasm32"))]
log::info!( log::info!(
"Mapped {} font faces in {}ms.", "Mapped {} font faces in {}ms.",
db.len(), db.len(),
@ -111,6 +115,7 @@ impl FontSystem {
font_matches_cache font_matches_cache
.entry(AttrsOwned::new(attrs)) .entry(AttrsOwned::new(attrs))
.or_insert_with(|| { .or_insert_with(|| {
#[cfg(not(target_arch = "wasm32"))]
let now = std::time::Instant::now(); let now = std::time::Instant::now();
let mut fonts = Vec::new(); let mut fonts = Vec::new();
@ -130,8 +135,11 @@ impl FontSystem {
fonts, fonts,
}); });
let elapsed = now.elapsed(); #[cfg(not(target_arch = "wasm32"))]
log::debug!("font matches for {:?} in {:?}", attrs, elapsed); {
let elapsed = now.elapsed();
log::debug!("font matches for {:?} in {:?}", attrs, elapsed);
}
font_matches font_matches
}) })