Mesh: Make edge_other_vert function branchless

This function shouldn't return invalid index. Instead assertion in used.
While the branchless code path may not be observably faster in current
code, it should work better with instruction level parallelism in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/114682
This commit is contained in:
Iliya Katueshenock
2023-11-13 18:46:04 +01:00
committed by Hans Goudey
parent 3f5654b491
commit a1a31659ea
2 changed files with 7 additions and 10 deletions

View File

@@ -269,17 +269,14 @@ inline int face_triangles_num(const int face_size)
/**
* Return the index of the edge's vertex that is not the \a vert.
* If neither edge vertex is equal to \a v, returns -1.
*/
inline int edge_other_vert(const int2 &edge, const int vert)
inline int edge_other_vert(const int2 edge, const int vert)
{
if (edge[0] == vert) {
return edge[1];
}
if (edge[1] == vert) {
return edge[0];
}
return -1;
BLI_assert(ELEM(vert, edge[0], edge[1]));
BLI_assert(edge[0] >= 0);
BLI_assert(edge[1] >= 0);
/* Order is important to avoid overflow. */
return (edge[0] - vert) + edge[1];
}
/** \} */

View File

@@ -54,7 +54,7 @@ static void shortest_paths(const Mesh &mesh,
visited[vert_i] = true;
for (const int edge_i : vert_to_edge[vert_i]) {
const int2 &edge = edges[edge_i];
const int neighbor_vert_i = edge[0] + edge[1] - vert_i;
const int neighbor_vert_i = bke::mesh::edge_other_vert(edge, vert_i);
if (visited[neighbor_vert_i]) {
continue;
}