diff options
author | Stanislav Malyshev <stas@php.net> | 2013-06-23 23:52:28 -0700 |
---|---|---|
committer | Stanislav Malyshev <stas@php.net> | 2013-06-23 23:52:28 -0700 |
commit | e3d625bc4ef1f66a9c8f82d3d188ea71c783b65f (patch) | |
tree | 19b34f73e038fc2f3d8eb01cf4f4aeedf3a445e9 | |
parent | 8aba119f5525663ab202e459929d7fb3271aef51 (diff) | |
download | php-git-e3d625bc4ef1f66a9c8f82d3d188ea71c783b65f.tar.gz |
small optimization
-rw-r--r-- | ext/intl/grapheme/grapheme_util.c | 15 | ||||
-rw-r--r-- | ext/intl/grapheme/grapheme_util.h | 2 |
2 files changed, 7 insertions, 10 deletions
diff --git a/ext/intl/grapheme/grapheme_util.c b/ext/intl/grapheme/grapheme_util.c index 595f0cc0f9..883fa0391a 100644 --- a/ext/intl/grapheme/grapheme_util.c +++ b/ext/intl/grapheme/grapheme_util.c @@ -155,6 +155,9 @@ int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigne status = U_ZERO_ERROR; bi = grapheme_get_break_iterator(u_break_iterator_buffer, &status TSRMLS_CC ); STRPOS_CHECK_STATUS(status, "Failed to get iterator"); + status = U_ZERO_ERROR; + ubrk_setText(bi, uhaystack, uhaystack_len, &status); + STRPOS_CHECK_STATUS(status, "Failed to set up iterator"); status = U_ZERO_ERROR; src = usearch_open(uneedle, uneedle_len, uhaystack, uhaystack_len, "", bi, &status); @@ -169,7 +172,7 @@ int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigne } if(offset != 0) { - offset_pos = grapheme_get_haystack_offset(bi, uhaystack, uhaystack_len, offset); + offset_pos = grapheme_get_haystack_offset(bi, offset); if(offset_pos == -1) { status = U_ILLEGAL_ARGUMENT_ERROR; STRPOS_CHECK_STATUS(status, "Invalid search offset"); @@ -191,7 +194,7 @@ int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigne } STRPOS_CHECK_STATUS(status, "Error looking up string"); if(char_pos != USEARCH_DONE && ubrk_isBoundary(bi, char_pos)) { - ret_pos = grapheme_count_graphemes(bi, uhaystack, char_pos); + ret_pos = grapheme_count_graphemes(bi, uhaystack,char_pos); if(puchar_pos) { *puchar_pos = char_pos; } @@ -290,18 +293,12 @@ int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t stri /* {{{ grapheme_get_haystack_offset - bump the haystack pointer based on the grapheme count offset */ -int grapheme_get_haystack_offset(UBreakIterator* bi, UChar *uhaystack, int32_t uhaystack_len, int32_t offset) +int grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset) { - UErrorCode status; int32_t pos; int32_t (*iter_op)(UBreakIterator* bi); int iter_incr; - if ( NULL != bi ) { - status = U_ZERO_ERROR; - ubrk_setText (bi, uhaystack, uhaystack_len, &status); - } - if ( 0 == offset ) { return 0; } diff --git a/ext/intl/grapheme/grapheme_util.h b/ext/intl/grapheme/grapheme_util.h index a2a1bc8873..14f3f22c45 100644 --- a/ext/intl/grapheme/grapheme_util.h +++ b/ext/intl/grapheme/grapheme_util.h @@ -37,7 +37,7 @@ int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t stri inline void *grapheme_memrchr_grapheme(const void *s, int c, int32_t n); -int grapheme_get_haystack_offset(UBreakIterator* bi, UChar *uhaystack, int32_t uhaystack_len, int32_t offset); +int grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset); int32_t grapheme_strrpos_ascii(unsigned char *haystack, int32_t haystack_len, unsigned char *needle, int32_t needle_len, int32_t offset); |