- commit
- 8af9bdb6042d92f405942772006196e264f4c989
- parent
- 8645e11f80f309621e05a515379a3b7960dc7ce5
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-01-12 18:42
perf: optimize getRole()
Diffstat
| M | lib/attrs.js | 12 | ++++++++---- |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/attrs.js b/lib/attrs.js
@@ -10,10 +10,14 @@ var getRole = function(el, candidates) {
10 10 return;
11 11 }
12 12 }
13 -1 for (var role in constants.roles) {
14 -1 var selector = (constants.roles[role].selectors || []).join(',');
15 -1 if (selector && (!candidates || candidates.includes(role)) && el.matches(selector)) {
16 -1 return role;
-1 13 var roles = candidates ? candidates : Object.keys(constants.roles);
-1 14 for (var role of roles) {
-1 15 var r = constants.roles[role];
-1 16 if (r) {
-1 17 var selector = (r.selectors || []).join(',');
-1 18 if (selector && el.matches(selector)) {
-1 19 return role;
-1 20 }
17 21 }
18 22 }
19 23 };