From cbcf421db795c3b8f8550ed1faecffeb76353fba Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 15 May 2025 14:53:11 -0400 Subject: [PATCH] Cleanup: Draw: Use StringRef for attribute names Avoid the need to measure string length potentially many times. --- source/blender/draw/intern/draw_cache_impl.hh | 5 +++-- source/blender/draw/intern/draw_cache_impl_curves.cc | 4 ++-- source/blender/draw/intern/draw_cache_impl_mesh.cc | 6 +++--- source/blender/draw/intern/draw_cache_impl_pointcloud.cc | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/source/blender/draw/intern/draw_cache_impl.hh b/source/blender/draw/intern/draw_cache_impl.hh index a35bf3cc40d..4d2349d44e2 100644 --- a/source/blender/draw/intern/draw_cache_impl.hh +++ b/source/blender/draw/intern/draw_cache_impl.hh @@ -12,6 +12,7 @@ #include "BLI_math_matrix_types.hh" #include "BLI_span.hh" +#include "BLI_string_ref.hh" struct GPUMaterial; namespace blender::gpu { @@ -138,7 +139,7 @@ blender::gpu::Batch *DRW_lattice_batch_cache_get_edit_verts(Lattice *lt); * stored, which will be filled by #DRW_shgroup_curves_create_sub. */ gpu::VertBuf **DRW_curves_texture_for_evaluated_attribute(Curves *curves, - const char *name, + StringRef name, bool *r_is_point_domain); blender::gpu::Batch *DRW_curves_batch_cache_get_edit_points(Curves *curves); @@ -156,7 +157,7 @@ void DRW_curves_batch_cache_create_requested(Object *ob); gpu::VertBuf *DRW_pointcloud_position_and_radius_buffer_get(Object *ob); -gpu::VertBuf **DRW_pointcloud_evaluated_attribute(PointCloud *pointcloud, const char *name); +gpu::VertBuf **DRW_pointcloud_evaluated_attribute(PointCloud *pointcloud, StringRef name); blender::gpu::Batch *DRW_pointcloud_batch_cache_get_dots(Object *ob); blender::gpu::Batch *DRW_pointcloud_batch_cache_get_edit_dots(PointCloud *pointcloud); diff --git a/source/blender/draw/intern/draw_cache_impl_curves.cc b/source/blender/draw/intern/draw_cache_impl_curves.cc index aacb4004844..d2349604eec 100644 --- a/source/blender/draw/intern/draw_cache_impl_curves.cc +++ b/source/blender/draw/intern/draw_cache_impl_curves.cc @@ -874,7 +874,7 @@ static bool ensure_attributes(const Curves &curves, return need_tf_update; } -static void request_attribute(Curves &curves, const char *name) +static void request_attribute(Curves &curves, const StringRef name) { CurvesBatchCache &cache = get_batch_cache(curves); CurvesEvalFinalCache &final_cache = cache.eval_cache.final; @@ -1033,7 +1033,7 @@ gpu::Batch *DRW_curves_batch_cache_get_edit_curves_lines(Curves *curves) } gpu::VertBuf **DRW_curves_texture_for_evaluated_attribute(Curves *curves, - const char *name, + const StringRef name, bool *r_is_point_domain) { CurvesBatchCache &cache = get_batch_cache(*curves); diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.cc b/source/blender/draw/intern/draw_cache_impl_mesh.cc index 50846f3144c..ffea229936e 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.cc +++ b/source/blender/draw/intern/draw_cache_impl_mesh.cc @@ -201,7 +201,7 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Object &object, } ListBase gpu_attrs = GPU_material_attributes(gpumat); LISTBASE_FOREACH (GPUMaterialAttribute *, gpu_attr, &gpu_attrs) { - const char *name = gpu_attr->name; + StringRef name = gpu_attr->name; eCustomDataType type = static_cast(gpu_attr->type); int layer = -1; std::optional domain; @@ -689,8 +689,8 @@ static void request_active_and_default_color_attributes(const Object &object, const CustomData &cd_vdata = mesh_cd_vdata_get_from_mesh(me_final); const CustomData &cd_ldata = mesh_cd_ldata_get_from_mesh(me_final); - auto request_color_attribute = [&](const char *name) { - if (name) { + auto request_color_attribute = [&](const StringRef name) { + if (!name.is_empty()) { int layer_index; eCustomDataType type; if (drw_custom_data_match_attribute(cd_vdata, name, &layer_index, &type)) { diff --git a/source/blender/draw/intern/draw_cache_impl_pointcloud.cc b/source/blender/draw/intern/draw_cache_impl_pointcloud.cc index b5cb525ab8e..28be98c1be0 100644 --- a/source/blender/draw/intern/draw_cache_impl_pointcloud.cc +++ b/source/blender/draw/intern/draw_cache_impl_pointcloud.cc @@ -400,7 +400,7 @@ gpu::VertBuf *DRW_pointcloud_position_and_radius_buffer_get(Object *ob) return pointcloud_position_and_radius_get(&pointcloud); } -gpu::VertBuf **DRW_pointcloud_evaluated_attribute(PointCloud *pointcloud, const char *name) +gpu::VertBuf **DRW_pointcloud_evaluated_attribute(PointCloud *pointcloud, const StringRef name) { const bke::AttributeAccessor attributes = pointcloud->attributes(); PointCloudBatchCache &cache = *pointcloud_batch_cache_get(*pointcloud);