1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Faster galley cache (#699)

* Speed up galley cache by only using the hash as key

This hashes the job but doesn't compare them with Eq,
which speeds up demo_with_tessellate__realistic by 5-6%,
winning back all the performance lost in
https://github.com/emilk/egui/pull/682

* Remove custom Eq/PartialEq code for LayoutJob and friends

* Silence clippy

* Unrelated clippy fixes
This commit is contained in:
Emil Ernerfeldt
2021-09-04 10:19:58 +02:00
committed by GitHub
parent 3b75a84d3b
commit 5f88d89f74
8 changed files with 34 additions and 59 deletions

View File

@@ -223,6 +223,7 @@ struct Highligher {}
#[cfg(not(feature = "syntect"))]
impl Highligher {
#[allow(clippy::unused_self, clippy::unnecessary_wraps)]
fn highlight(&self, is_dark_mode: bool, mut text: &str, _language: &str) -> Option<LayoutJob> {
// Extremely simple syntax highlighter for when we compile without syntect
@@ -269,7 +270,7 @@ impl Highligher {
while !text.is_empty() {
if text.starts_with("//") {
let end = text.find('\n').unwrap_or(text.len());
let end = text.find('\n').unwrap_or_else(|| text.len());
job.append(&text[..end], 0.0, comment_format);
text = &text[end..];
} else if text.starts_with('"') {
@@ -277,14 +278,14 @@ impl Highligher {
.find('"')
.map(|i| i + 2)
.or_else(|| text.find('\n'))
.unwrap_or(text.len());
.unwrap_or_else(|| text.len());
job.append(&text[..end], 0.0, quoted_string_format);
text = &text[end..];
} else if text.starts_with(|c: char| c.is_ascii_alphanumeric()) {
let end = text[1..]
.find(|c: char| !c.is_ascii_alphanumeric())
.map(|i| i + 1)
.unwrap_or(text.len());
.unwrap_or_else(|| text.len());
let word = &text[..end];
if is_keyword(word) {
job.append(word, 0.0, keyword_format);
@@ -296,7 +297,7 @@ impl Highligher {
let end = text[1..]
.find(|c: char| !c.is_ascii_whitespace())
.map(|i| i + 1)
.unwrap_or(text.len());
.unwrap_or_else(|| text.len());
job.append(&text[..end], 0.0, whitespace_format);
text = &text[end..];
} else {