mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
chore: Reduce number of calls to getAttribute (#6119)
* Reduce number of calls to getAttribute ~1% speedup. * Improve comment.
This commit is contained in:
@@ -56,11 +56,14 @@ const XY_STYLE_REGEX =
|
||||
const getRelativeXY = function(element) {
|
||||
const xy = new Coordinate(0, 0);
|
||||
// First, check for x and y attributes.
|
||||
const x = element.getAttribute('x');
|
||||
// Checking for the existence of x/y properties is faster than getAttribute.
|
||||
// However, x/y contains an SVGAnimatedLength object, so rely on getAttribute
|
||||
// to get the number.
|
||||
const x = element.x && element.getAttribute('x');
|
||||
const y = element.y && element.getAttribute('y');
|
||||
if (x) {
|
||||
xy.x = parseInt(x, 10);
|
||||
}
|
||||
const y = element.getAttribute('y');
|
||||
if (y) {
|
||||
xy.y = parseInt(y, 10);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user