Skip to content

Commit

Permalink
Merge pull request #12309 from rwjblue/use-cache-for-tagname-operations
Browse files Browse the repository at this point in the history
Use `Cache` for tagname operations.
  • Loading branch information
rwjblue committed Sep 9, 2015
2 parents 0ff1f46 + c1dd47a commit 2bca168
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions packages/ember-htmlbars/lib/hooks/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { assert } from 'ember-metal/debug';
import ComponentNodeManager from 'ember-htmlbars/node-managers/component-node-manager';
import buildComponentTemplate, { buildHTMLTemplate } from 'ember-views/system/build-component-template';
import lookupComponent from 'ember-htmlbars/utils/lookup-component';
import Cache from 'ember-metal/cache';

var IS_ANGLE_CACHE = new Cache(1000, function(key) {
return key.match(/^(@?)<(.*)>$/);
});

var CONTAINS_DASH = new Cache(1000, function(key) {
return key.indexOf('-') !== -1;
});

export default function componentHook(renderNode, env, scope, _tagName, params, attrs, templates, visitor) {
var state = renderNode.getState();
Expand All @@ -17,15 +26,15 @@ export default function componentHook(renderNode, env, scope, _tagName, params,
let isTopLevel = false;
let isDasherized = false;

let angles = tagName.match(/^(@?)<(.*)>$/);
let angles = IS_ANGLE_CACHE.get(tagName);

if (angles) {
tagName = angles[2];
isAngleBracket = true;
isTopLevel = !!angles[1];
}

if (tagName.indexOf('-') !== -1) {
if (CONTAINS_DASH.get(tagName)) {
isDasherized = true;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/ember-metal/lib/cache.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import dictionary from 'ember-metal/dictionary';
import EmptyObject from 'ember-metal/empty_object';
export default Cache;

function Cache(limit, func) {
this.store = dictionary(null);
this.store = new EmptyObject();
this.size = 0;
this.misses = 0;
this.hits = 0;
Expand Down Expand Up @@ -44,7 +44,7 @@ Cache.prototype = {
},

purge() {
this.store = dictionary(null);
this.store = new EmptyObject();
this.size = 0;
this.hits = 0;
this.misses = 0;
Expand Down

0 comments on commit 2bca168

Please sign in to comment.