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:
@@ -9,10 +9,32 @@
|
||||
#include <Format.h>
|
||||
|
||||
|
||||
namespace icu {
|
||||
class MessageFormat;
|
||||
class UnicodeString;
|
||||
}
|
||||
|
||||
|
||||
class BMessageFormat: public BFormat {
|
||||
public:
|
||||
status_t Format(BString& buffer, const BString message,
|
||||
const int32 arg);
|
||||
BMessageFormat(const BString pattern);
|
||||
~BMessageFormat();
|
||||
|
||||
status_t InitCheck();
|
||||
|
||||
status_t SetLanguage(const BLanguage& newLanguage);
|
||||
status_t SetFormattingConventions(
|
||||
const BFormattingConventions&
|
||||
conventions);
|
||||
|
||||
status_t Format(BString& buffer, const int32 arg) const;
|
||||
|
||||
private:
|
||||
status_t _Initialize(const icu::UnicodeString&);
|
||||
|
||||
private:
|
||||
status_t fInitStatus;
|
||||
icu::MessageFormat* fFormatter;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user