Skip to content

Commit e3d625b

Browse files
committed
small optimization
1 parent 8aba119 commit e3d625b

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

ext/intl/grapheme/grapheme_util.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigne
155155
status = U_ZERO_ERROR;
156156
bi = grapheme_get_break_iterator(u_break_iterator_buffer, &status TSRMLS_CC );
157157
STRPOS_CHECK_STATUS(status, "Failed to get iterator");
158+
status = U_ZERO_ERROR;
159+
ubrk_setText(bi, uhaystack, uhaystack_len, &status);
160+
STRPOS_CHECK_STATUS(status, "Failed to set up iterator");
158161

159162
status = U_ZERO_ERROR;
160163
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
169172
}
170173

171174
if(offset != 0) {
172-
offset_pos = grapheme_get_haystack_offset(bi, uhaystack, uhaystack_len, offset);
175+
offset_pos = grapheme_get_haystack_offset(bi, offset);
173176
if(offset_pos == -1) {
174177
status = U_ILLEGAL_ARGUMENT_ERROR;
175178
STRPOS_CHECK_STATUS(status, "Invalid search offset");
@@ -191,7 +194,7 @@ int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigne
191194
}
192195
STRPOS_CHECK_STATUS(status, "Error looking up string");
193196
if(char_pos != USEARCH_DONE && ubrk_isBoundary(bi, char_pos)) {
194-
ret_pos = grapheme_count_graphemes(bi, uhaystack, char_pos);
197+
ret_pos = grapheme_count_graphemes(bi, uhaystack,char_pos);
195198
if(puchar_pos) {
196199
*puchar_pos = char_pos;
197200
}
@@ -290,18 +293,12 @@ int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t stri
290293

291294

292295
/* {{{ grapheme_get_haystack_offset - bump the haystack pointer based on the grapheme count offset */
293-
int grapheme_get_haystack_offset(UBreakIterator* bi, UChar *uhaystack, int32_t uhaystack_len, int32_t offset)
296+
int grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset)
294297
{
295-
UErrorCode status;
296298
int32_t pos;
297299
int32_t (*iter_op)(UBreakIterator* bi);
298300
int iter_incr;
299301

300-
if ( NULL != bi ) {
301-
status = U_ZERO_ERROR;
302-
ubrk_setText (bi, uhaystack, uhaystack_len, &status);
303-
}
304-
305302
if ( 0 == offset ) {
306303
return 0;
307304
}

ext/intl/grapheme/grapheme_util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t stri
3737

3838
inline void *grapheme_memrchr_grapheme(const void *s, int c, int32_t n);
3939

40-
int grapheme_get_haystack_offset(UBreakIterator* bi, UChar *uhaystack, int32_t uhaystack_len, int32_t offset);
40+
int grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset);
4141

4242
int32_t grapheme_strrpos_ascii(unsigned char *haystack, int32_t haystack_len, unsigned char *needle, int32_t needle_len, int32_t offset);
4343

0 commit comments

Comments
 (0)