Closed
Bug 850855
Opened 12 years ago
Closed 12 years ago
Clean up context's get*
Categories
(L20n :: JS Library, defect, P1)
Tracking
(Not tracked)
RESOLVED
FIXED
1.0 beta
People
(Reporter: zbraniecki, Assigned: stas)
References
Details
(Keywords: APIchange)
Attachments
(1 file, 2 obsolete files)
8.12 KB,
patch
|
zbraniecki
:
review+
|
Details | Diff | Splinter Review |
We currently have a mess inside get* functions. Both code wise and API wise.
We need to clean this up. Arguments, return values, code flow, fallbacks, error reporting.
Assignee | ||
Updated•12 years ago
|
Assignee: nobody → gandalf
Priority: -- → P1
Target Milestone: --- → 1.0 beta
Reporter | ||
Updated•12 years ago
|
Assignee: gandalf → stas
Assignee | ||
Comment 1•12 years ago
|
||
The patch implements a recursive getFromLocale instead of a _get with a while loop.
It also defaults to getEntity. When doing ctx.get, the code uses getEntity but just returns the string value.
There shouldn't be any perf implications: most of the times, if you care about the attrs, you'll use ctx.getEntity anyways. If you're using ctx.get, it's probably with an entity which doesn't have any public attributes.
Attachment #737538 -
Flags: review?(gandalf)
Assignee | ||
Comment 2•12 years ago
|
||
I rebased the patch on top of the current master.
Attachment #737538 -
Attachment is obsolete: true
Attachment #737538 -
Flags: review?(gandalf)
Attachment #737562 -
Flags: review?(gandalf)
Reporter | ||
Comment 3•12 years ago
|
||
Comment on attachment 737562 [details] [diff] [review]
Patch (rebased)
>diff --git a/lib/compiler.js b/lib/compiler.js
>index 85e55e7..5c889a6 100644
>--- a/lib/compiler.js
>+++ b/lib/compiler.js
>@@ -235,6 +235,7 @@
> this.local = node.local || false;
> this.index = [];
> this.attributes = {};
>+ this.publicAttributes = [];
> var i;
> for (i = 0; i < node.index.length; i++) {
> this.index.push(Expression(node.index[i], this));
>@@ -242,6 +243,9 @@
> for (i = 0; i < node.attrs.length; i++) {
> var attr = node.attrs[i];
> this.attributes[attr.key.name] = new Attribute(attr, this);
>+ if (!attr.local) {
>+ this.publicAttributes.push(attr.key.name);
>+ }
> }
> this.value = Expression(node.value, this, this.index);
> }
>@@ -284,8 +288,8 @@
> value: this.getString(ctxdata),
> attributes: {}
> };
>- for (var name in this.attributes) {
>- entity.attributes[name] = this.attributes[name].getString(ctxdata);
>+ for (var i = 0, attr; attr = this.publicAttributes[i]; i++) {
>+ entity.attributes[attr] = this.attributes[attr].getString(ctxdata);
> }
Why is publicAttributes better than checking for .local here?
>diff --git a/lib/context.js b/lib/context.js
>index 23d40e7..376d625 100644
>--- a/lib/context.js
>+++ b/lib/context.js
>@@ -204,13 +204,46 @@
> },
> };
> var _listeners = [];
>- var _pending = [];
>+ var _pending = {
>+ get: [],
>+ getEntity: [],
>+ };
Can we not use _pending here and require context to be ready before any get is fired?
I think it would be suitable for 1.0, extendable for Next and would simplify the code.
Assignee | ||
Comment 4•12 years ago
|
||
(In reply to Zbigniew Braniecki [:gandalf] from comment #3)
> Comment on attachment 737562 [details] [diff] [review]
> Patch (rebased)
>
> >diff --git a/lib/compiler.js b/lib/compiler.js
> >index 85e55e7..5c889a6 100644
> >--- a/lib/compiler.js
> >+++ b/lib/compiler.js
> >@@ -235,6 +235,7 @@
> > this.local = node.local || false;
> > this.index = [];
> > this.attributes = {};
> >+ this.publicAttributes = [];
> > var i;
> > for (i = 0; i < node.index.length; i++) {
> > this.index.push(Expression(node.index[i], this));
> >@@ -242,6 +243,9 @@
> > for (i = 0; i < node.attrs.length; i++) {
> > var attr = node.attrs[i];
> > this.attributes[attr.key.name] = new Attribute(attr, this);
> >+ if (!attr.local) {
> >+ this.publicAttributes.push(attr.key.name);
> >+ }
> > }
> > this.value = Expression(node.value, this, this.index);
> > }
> >@@ -284,8 +288,8 @@
> > value: this.getString(ctxdata),
> > attributes: {}
> > };
> >- for (var name in this.attributes) {
> >- entity.attributes[name] = this.attributes[name].getString(ctxdata);
> >+ for (var i = 0, attr; attr = this.publicAttributes[i]; i++) {
> >+ entity.attributes[attr] = this.attributes[attr].getString(ctxdata);
> > }
>
> Why is publicAttributes better than checking for .local here?
publicAttributes is filled in during the initialization of the Entity, so only once. Checking for .local here means checking every time we call Entity.getEntity (I'll rename this to Entity.get).
From my tests, on an attribute-sparse file, there's negligible performance difference. For attribute-heavy files, publicAttributes approach can be up to 15% faster,
> >diff --git a/lib/context.js b/lib/context.js
> >index 23d40e7..376d625 100644
> >--- a/lib/context.js
> >+++ b/lib/context.js
> >@@ -204,13 +204,46 @@
> > },
> > };
> > var _listeners = [];
> >- var _pending = [];
> >+ var _pending = {
> >+ get: [],
> >+ getEntity: [],
> >+ };
>
> Can we not use _pending here and require context to be ready before any get
> is fired?
>
> I think it would be suitable for 1.0, extendable for Next and would simplify
> the code.
OK, I'll change it.
Assignee | ||
Comment 5•12 years ago
|
||
This patch also fixes bug 862101.
Attachment #737562 -
Attachment is obsolete: true
Attachment #737562 -
Flags: review?(gandalf)
Attachment #737859 -
Flags: review?(gandalf)
Reporter | ||
Updated•12 years ago
|
Attachment #737859 -
Flags: review?(gandalf) → review+
Assignee | ||
Comment 6•12 years ago
|
||
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Reporter | ||
Comment 7•12 years ago
|
||
Is it possible that this regressed string compilation? It seems like the strings are always returned as simple ones now.
Flags: needinfo?(stas)
You need to log in
before you can comment on or make changes to this bug.
Description
•