Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit e927193

Browse files
committed
perf($interpolate): optimize value stringification
previously we stringified numbers via toJson which was expensive, I optimized the code so that toJson is invoked only if really necessary Closes #7501
1 parent 0dfbf8a commit e927193

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/ng/interpolate.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,20 @@ function $InterpolateProvider() {
216216
};
217217

218218
var stringify = function (value) {
219-
if (isUndefined(value) || value === null) {
220-
value = '';
219+
if (value == null) { // null || undefined
220+
return '';
221221
}
222-
if (typeof value != 'string') {
223-
value = toJson(value);
222+
switch (typeof value) {
223+
case 'string': {
224+
break;
225+
}
226+
case 'number': {
227+
value = '' + value;
228+
break;
229+
}
230+
default: {
231+
value = toJson(value);
232+
}
224233
}
225234

226235
return value;

0 commit comments

Comments
 (0)