SVGHMI: Switch from {object} to Map for "updates" global, for performance but also preventing wierd behaviour when iterating
--- a/svghmi/svghmi.js Thu Feb 18 12:02:28 2021 +0100
+++ b/svghmi/svghmi.js Fri Feb 19 10:03:00 2021 +0100
@@ -51,12 +51,10 @@
// Apply updates recieved through ws.onmessage to subscribed widgets
function apply_updates() {
- for(let index in updates){
- // serving as a key, index becomes a string
- // -> pass Number(index) instead
- dispatch_value(Number(index), updates[index]);
- delete updates[index];
- }
+ updates.forEach((value, index) => {
+ dispatch_value(index, value);
+ });
+ updates.clear();
}
// Called on requestAnimationFrame, modifies DOM
@@ -110,7 +108,7 @@
if(iectype != undefined){
let dvgetter = dvgetters[iectype];
let [value, bytesize] = dvgetter(dv,i);
- updates[index] = value;
+ updates.set(index, value);
i += bytesize;
} else {
throw new Error("Unknown index "+index);
@@ -292,7 +290,7 @@
function send_hmi_value(index, value) {
if(index > last_remote_index){
- updates[index] = value;
+ updates.set(index, value);
if(persistent_indexes.has(index)){
let varname = persistent_indexes.get(index);
--- a/svghmi/widgets_common.ysl2 Thu Feb 18 12:02:28 2021 +0100
+++ b/svghmi/widgets_common.ysl2 Fri Feb 19 10:03:00 2021 +0100
@@ -96,7 +96,7 @@
]);
var persistent_indexes = new Map();
var cache = hmitree_types.map(_ignored => undefined);
- var updates = {};
+ var updates = new Map();
function page_local_index(varname, pagename){
let pagevars = hmi_locals[pagename];
@@ -116,7 +116,7 @@
let defaultval = local_defaults[varname];
if(defaultval != undefined) {
cache[new_index] = defaultval;
- updates[new_index] = defaultval;
+ updates.set(new_index, defaultval);
if(persistent_locals.has(varname))
persistent_indexes.set(new_index, varname);
}