BMessageFormat: parse the pattern at construction

* Instead of parsing the pattern everytime Format() is called, parse it
only once when the object is created.
* Adjust all callers to make use of the feature and reuse the instance
as much as possible. This also allows calling B_TRANSLATE only once
instead of everytime the formatting needs to be done. We use either a
static instance (when the message pattern is constant) or a field (when
it is not known to be constant).
* Since the BMessageFormat instances are now reused, add locking to
avoid race conditions (ICU itself is thread safe, but the format pattern
is recreated when the locale is changed)
This commit is contained in:
Adrien Destugues
2014-10-08 15:12:48 +02:00
parent 0e7fcd84af
commit 961fdd8cc3
15 changed files with 179 additions and 59 deletions
+5 -3
View File
@@ -443,10 +443,12 @@ AboutView::AboutView()
B_ALIGN_VERTICAL_UNSET));
// CPU count, type and clock speed
BString processorLabel;
BMessageFormat().Format(processorLabel, B_TRANSLATE_COMMENT(
static BMessageFormat format(B_TRANSLATE_COMMENT(
"{0, plural, one{Processor:} other{# Processors:}}",
"\"Processor:\" or \"2 Processors:\""), systemInfo.cpu_count);
"\"Processor:\" or \"2 Processors:\""));
BString processorLabel;
format.Format(processorLabel, systemInfo.cpu_count);
uint32 topologyNodeCount = 0;
cpu_topology_node_info* topology = NULL;