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

Optimize: add #[inline(always)] to various low-level things

saves up to 20% (text tesselation), and at least 5% overall
This commit is contained in:
Emil Ernerfeldt
2021-03-28 23:16:19 +02:00
parent ccc501f302
commit 46425f1e38
10 changed files with 144 additions and 7 deletions

View File

@@ -92,6 +92,7 @@ impl Mesh {
}
}
#[inline(always)]
pub fn colored_vertex(&mut self, pos: Pos2, color: Color32) {
debug_assert!(self.texture_id == TextureId::Egui);
self.vertices.push(Vertex {
@@ -102,6 +103,7 @@ impl Mesh {
}
/// Add a triangle.
#[inline(always)]
pub fn add_triangle(&mut self, a: u32, b: u32, c: u32) {
self.indices.push(a);
self.indices.push(b);
@@ -110,12 +112,14 @@ impl Mesh {
/// Make room for this many additional triangles (will reserve 3x as many indices).
/// See also `reserve_vertices`.
#[inline(always)]
pub fn reserve_triangles(&mut self, additional_triangles: usize) {
self.indices.reserve(3 * additional_triangles);
}
/// Make room for this many additional vertices.
/// See also `reserve_triangles`.
#[inline(always)]
pub fn reserve_vertices(&mut self, additional: usize) {
self.vertices.reserve(additional);
}
@@ -151,6 +155,7 @@ impl Mesh {
}
/// Uniformly colored rectangle.
#[inline(always)]
pub fn add_colored_rect(&mut self, rect: Rect, color: Color32) {
debug_assert!(self.texture_id == TextureId::Egui);
self.add_rect_with_uv(rect, [WHITE_UV, WHITE_UV].into(), color)