iVis-at-Bilkent / cose-base

Core module for compound spring embedder based layout styles
MIT License
9 stars 2 forks source link

Using Array.prototype.push() instead of Array.prototype.concat() in appropriate places #10

Open metincansiper opened 2 years ago

metincansiper commented 2 years ago

Array.prototype.concat() returns a new array so using it to add all element of an array to the other one would be inefficient in some cases. I listed the code segments where I believe it could worth updating that code segment to add each element using Array.prototype.push() instead of using Array.prototype.concat() (some of them are from this repository and some of them are from the layout-base repository):

I believe that the line below would not make a big difference but I think I can still add it to this list while mentioning the similar updates. I guess that it would perform slightly better if similar updates would be done there (I think it may be dependent on how large would source.getEdgeListToNode(target) be). Also, I recognized that LNode.prototype.getEdgeListToNode() already builds and returns a new list (https://github.com/iVis-at-Bilkent/layout-base/blob/9877008db719062ed89c1627d8c883386d9f0a4b/src/LNode.js#L144). Therefore, if I am not missing something, it would be safe to directly initialize the edgeList variable as var edgeList = source.getEdgeListToNode(target) above this line. I do not know if it would make a nontrivial difference but I can still mention that a similar case (just about initializing edgeList as empty vs assigning it directly to source.getEdgeListToNode(target)) would exist in the related java code as well (https://github.com/iVis-at-Bilkent/chilay/blob/605e77732a6f06da2081e2d89a68084c1e508cdb/src/main/java/org/ivis/layout/cose/CoSELayout.java#L388)