1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Enable or_fun_call lint to avoid unnecessary allocations (#7754)

### What

From the [lint
description](https://rust-lang.github.io/rust-clippy/master/index.html?search=or_fu#or_fun_call):

> The function will always be called. This is only bad if it allocates
or does some non-trivial amount of work.

But also:

> If the function has side-effects, not calling it will change the
semantic of the program, but you shouldn’t rely on that.
> 
> The lint also cannot figure out whether the function you call is
actually expensive to call or not.

Still worth it to keep our happy paths clean, imo.
This commit is contained in:
Jochen Görtler
2025-12-05 10:46:34 +01:00
committed by GitHub
parent 3fcdab4ebd
commit 2dbfe3a083
19 changed files with 44 additions and 33 deletions

View File

@@ -298,7 +298,8 @@ impl CubicBezierShape {
/// the number of points is determined by the tolerance.
/// the points may not be evenly distributed in the range [0.0,1.0] (t value)
pub fn flatten(&self, tolerance: Option<f32>) -> Vec<Pos2> {
let tolerance = tolerance.unwrap_or((self.points[0].x - self.points[3].x).abs() * 0.001);
let tolerance =
tolerance.unwrap_or_else(|| (self.points[0].x - self.points[3].x).abs() * 0.001);
let mut result = vec![self.points[0]];
self.for_each_flattened_with_t(tolerance, &mut |p, _t| {
result.push(p);
@@ -313,7 +314,8 @@ impl CubicBezierShape {
/// The result will be a vec of vec of Pos2. it will store two closed aren in different vec.
/// The epsilon is used to compare a float value.
pub fn flatten_closed(&self, tolerance: Option<f32>, epsilon: Option<f32>) -> Vec<Vec<Pos2>> {
let tolerance = tolerance.unwrap_or((self.points[0].x - self.points[3].x).abs() * 0.001);
let tolerance =
tolerance.unwrap_or_else(|| (self.points[0].x - self.points[3].x).abs() * 0.001);
let epsilon = epsilon.unwrap_or(1.0e-5);
let mut result = Vec::new();
let mut first_half = Vec::new();
@@ -519,7 +521,8 @@ impl QuadraticBezierShape {
/// the number of points is determined by the tolerance.
/// the points may not be evenly distributed in the range [0.0,1.0] (t value)
pub fn flatten(&self, tolerance: Option<f32>) -> Vec<Pos2> {
let tolerance = tolerance.unwrap_or((self.points[0].x - self.points[2].x).abs() * 0.001);
let tolerance =
tolerance.unwrap_or_else(|| (self.points[0].x - self.points[2].x).abs() * 0.001);
let mut result = vec![self.points[0]];
self.for_each_flattened_with_t(tolerance, &mut |p, _t| {
result.push(p);