Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

String.format() and L() performance...

$
0
0

Hi,

It's my understanding that String.format() uses native code. Is this correct?

I have a multi-lingual app that relies heavily on String.format() and L(). I use these methods within loops for hundreds of items at a time, and was wondering if this could be somehow optimized.

If there's a bit of a performance hit calling String.format() and going over the bridge, would it be better to replace it for a pure javascript format method that uses replace? I don't need the extended features of printf formatting (e.g., "%.2f"), just basic string replacements "%s" for i18n.

Also, when using L() in loops, would it be better to move those string templates outside the loop? Like this:

var t1 = L('template1'), t2 = L('template2'), t3 = L('template3'),;
for (var i = 0; i < j; i++) {
    label1.text = String.format(t1, val1[i], val1[i], val1[i]);
    label2.text = String.format(t2, val2[i], val2[i], val2[i]);
    label3.text = String.format(t3, val3[i], val3[i], val3[i]);}
Thanks! -e

Viewing all articles
Browse latest Browse all 8068

Trending Articles