Skip to content

Commit

Permalink
Revise node path caching #2028
Browse files Browse the repository at this point in the history
- Use the hash function for node path cache keys
- Cache node paths per-renderer rather than per-node
  • Loading branch information
maxkfranz committed Dec 8, 2017
1 parent b2ea115 commit 137a7a6
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/extensions/renderer/canvas/drawing-nodes.js
@@ -1,6 +1,7 @@
/* global Path2D */

let is = require( '../../../is' );
let is = require('../../../is');
let util = require('../../../util');

let CRp = {};

Expand Down Expand Up @@ -91,17 +92,24 @@ CRp.drawNode = function( context, node, shiftToOriginWithBb, drawLabel ){
let shapePts = node.pstyle('shape-polygon-points').pfValue;

if( usePaths ){
let pathCacheKey = styleShape + '$' + nodeWidth + '$' + nodeHeight + ( styleShape === 'polygon' ? '$' + shapePts.join('$') : '' );

context.translate( pos.x, pos.y );

if( rs.pathCacheKey === pathCacheKey ){
path = rs.pathCache;
let pathCache = r.nodePathCache = r.nodePathCache || [];

let key = util.hashStrings(
styleShape === 'polygon' ? styleShape + ',' + shapePts.join(',') : styleShape,
'' + nodeHeight,
'' + nodeWidth
);

let cachedPath = pathCache[ key ];

if( cachedPath != null ){
path = cachedPath;
pathCacheHit = true;
} else {
path = new Path2D();
rs.pathCacheKey = pathCacheKey;
rs.pathCache = path;
pathCache[ key ] = path;
}
}

Expand Down

0 comments on commit 137a7a6

Please sign in to comment.