summaryrefslogtreecommitdiff
path: root/utf8.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-03-20 12:13:46 +0000
committerNicholas Clark <nick@ccl4.org>2006-03-20 12:13:46 +0000
commiteb63405fd7f24e5bad9ec7f42adce6af6314724e (patch)
treef650f9c11abfe99005b820a25b01b249cfd302e2 /utf8.c
parent3fdeee05312bf904b2b698f85963a6d644083194 (diff)
downloadperl-eb63405fd7f24e5bad9ec7f42adce6af6314724e.tar.gz
The two loops in Perl_utf8_distance can be merged.
p4raw-id: //depot/perl@27552
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c44
1 files changed, 20 insertions, 24 deletions
diff --git a/utf8.c b/utf8.c
index e5079cb709..af63ac3766 100644
--- a/utf8.c
+++ b/utf8.c
@@ -705,41 +705,37 @@ Perl_utf8_distance(pTHX_ const U8 *a, const U8 *b)
{
dVAR;
IV off = 0;
+ IV sign = 1;
/* Note: cannot use UTF8_IS_...() too eagerly here since e.g.
* the bitops (especially ~) can create illegal UTF-8.
* In other words: in Perl UTF-8 is not just for Unicode. */
if (a < b) {
- while (a < b) {
- const U8 c = UTF8SKIP(a);
- if (b - a < c)
- goto warn_and_return;
- a += c;
- off--;
- }
+ const U8 *const temp = a;
+ a = b;
+ b = temp;
+ sign = -1;
}
- else {
- while (b < a) {
- const U8 c = UTF8SKIP(b);
-
- if (a - b < c) {
- warn_and_return:
- if (ckWARN_d(WARN_UTF8)) {
- if (PL_op)
- Perl_warner(aTHX_ packWARN(WARN_UTF8),
- "%s in %s", unees, OP_DESC(PL_op));
- else
- Perl_warner(aTHX_ packWARN(WARN_UTF8), unees);
- }
- return off;
+
+ while (b < a) {
+ const U8 c = UTF8SKIP(b);
+
+ if (a - b < c) {
+ if (ckWARN_d(WARN_UTF8)) {
+ if (PL_op)
+ Perl_warner(aTHX_ packWARN(WARN_UTF8),
+ "%s in %s", unees, OP_DESC(PL_op));
+ else
+ Perl_warner(aTHX_ packWARN(WARN_UTF8), unees);
}
- b += c;
- off++;
+ return off * sign;
}
+ b += c;
+ off++;
}
- return off;
+ return off * sign;
}
/*