The existing logic to copy `BMesh` custom data layers to `Mesh` attribute arrays was quite complicated, and incorrect in some cases when the source and destinations didn't have the same layers. The functions leave a lot to be desired in general, since they have a lot of redundant complexity that ends up doing the same thing for every element. The problem in #104154 was that the "rest_position" attribute overwrote the mesh positions since it has the same type and the positions weren't copied. This same problem has shown up in boolean attribute conversion in the past. Other changes fixed some specific cases but I think a larger change is the only proper solution. This patch adds preprocessing before looping over all elements to find the basic information for copying the relevant layers, taking layer names into account. The preprocessing makes the hot loops simpler. In a simple file with a 1 million vertex grid, I observed a 6% improvement animation playback framerate in edit mode with a simple geometry nodes modifier, from 5 to 5.3 FPS. Fixes #104154, #104348 Pull Request #104421