Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Cache for tagname operations. #12309

Merged
merged 1 commit into from
Sep 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(/^(@?)<(.*)>$/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this RegExp looks like kirby 👍

});

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