diff options
Diffstat (limited to 'ext/intl/msgformat/msgformat_helpers.cpp')
-rwxr-xr-x | ext/intl/msgformat/msgformat_helpers.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/ext/intl/msgformat/msgformat_helpers.cpp b/ext/intl/msgformat/msgformat_helpers.cpp index 503dca9ad9..1a7dc89c87 100755 --- a/ext/intl/msgformat/msgformat_helpers.cpp +++ b/ext/intl/msgformat/msgformat_helpers.cpp @@ -100,7 +100,9 @@ double umsg_helper_zval_to_millis(zval *z, UErrorCode *status TSRMLS_DC) { return rv; } -static HashTable *umsg_parse_format(const MessagePattern& mp, UErrorCode& uec) +static HashTable *umsg_parse_format(MessageFormatter_object *mfo, + const MessagePattern& mp, + UErrorCode& uec) { HashTable *ret; int32_t parts_count; @@ -109,6 +111,11 @@ static HashTable *umsg_parse_format(const MessagePattern& mp, UErrorCode& uec) return NULL; } + if (mfo->mf_data.arg_types) { + /* already cached */ + return mfo->mf_data.arg_types; + } + /* Hash table will store Formattable::Type objects directly, * so no need for destructor */ ALLOC_HASHTABLE(ret); @@ -235,22 +242,24 @@ static HashTable *umsg_parse_format(const MessagePattern& mp, UErrorCode& uec) return NULL; } + mfo->mf_data.arg_types = ret; + return ret; } -U_CFUNC void umsg_format_helper(UMessageFormat *fmt, HashTable *args, UChar **formatted, int *formatted_len, UErrorCode *status TSRMLS_DC) +U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, HashTable *args, UChar **formatted, int *formatted_len, UErrorCode *status TSRMLS_DC) { int arg_count = zend_hash_num_elements(args); std::vector<Formattable> fargs; std::vector<UnicodeString> farg_names; - MessageFormat *mf = (MessageFormat *) fmt; + MessageFormat *mf = (MessageFormat *)mfo->mf_data.umsgf; const MessagePattern mp = MessageFormatAdapter::getMessagePattern(mf); HashTable *types; fargs.resize(arg_count); farg_names.resize(arg_count); - types = umsg_parse_format(mp, *status); + types = umsg_parse_format(mfo, mp, *status); if (U_FAILURE(*status)) { return; } @@ -391,9 +400,6 @@ string_arg: //XXX: make function } } // visiting each argument - zend_hash_destroy(types); - efree(types); - if (U_FAILURE(*status)){ return; } |