summaryrefslogtreecommitdiff
path: root/ext/intl/msgformat/msgformat_helpers.cpp
diff options
context:
space:
mode:
authorGustavo André dos Santos Lopes <cataphract@php.net>2012-05-06 16:31:52 +0200
committerGustavo André dos Santos Lopes <cataphract@php.net>2012-05-13 20:53:05 +0100
commit20dd5ccf19916a290973a2e25de4eed59b169093 (patch)
tree5a7897a4541969a625cff7eb1b42b2c388c92d88 /ext/intl/msgformat/msgformat_helpers.cpp
parent407455876e486df45a6b6c91b483060b0479a0b3 (diff)
downloadphp-git-20dd5ccf19916a290973a2e25de4eed59b169093.tar.gz
Cache arguments type info in MessageFormatter.
Diffstat (limited to 'ext/intl/msgformat/msgformat_helpers.cpp')
-rwxr-xr-xext/intl/msgformat/msgformat_helpers.cpp20
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;
}