molstar
molstar copied to clipboard
improve bond iterator allocations by using a state/context object
Creating two closures inside a loop isn't exactly cheap. Tho I guess it shouldn't be a problem in this particular case.
If you feel like it in the future, there is a way to avoid creating the closure with something like this:
function eachIntraBondedAtom(unit, idx, cb, thisArg?: State) {
for (const b of ...) {
cb.call(thisArg, x, y);
}
}
and then the callback can be a top-level function like this:
function eachBond(this: State, x, y) {
this.whatever = x;
}
Originally posted by @dsehnal in https://github.com/molstar/molstar/pull/797#discussion_r1186795226