Fossil SCM
A little bit faster, by only accessing *z once and using bit-operations in stead of comparisions.
Commit
f246ea43130abcd5244754c717cb8127aecfb611
Parent
cc09e00358fd274…
1 file changed
+5
-3
+5
-3
| --- src/lookslike.c | ||
| +++ src/lookslike.c | ||
| @@ -219,15 +219,17 @@ | ||
| 219 | 219 | /* if the byte is outside the allowed range for this definition, |
| 220 | 220 | * return invalid */ |
| 221 | 221 | return LOOK_INVALID; |
| 222 | 222 | } |
| 223 | 223 | if( len > 2 ){ |
| 224 | - if( (*z<0x80) || (*z++>0xBF) ){ | |
| 225 | - return LOOK_INVALID; | |
| 224 | + /* if the next byte is not between 0x80 and 0xBF, return invalid */ | |
| 225 | + if( (*z++&0xC0)!=0x80 ){ | |
| 226 | + return LOOK_INVALID; | |
| 226 | 227 | } |
| 227 | 228 | if( len > 3 ){ |
| 228 | - if( (*z<0x80) || (*z++>0xBF) ){ | |
| 229 | + /* if the next byte is not between 0x80 and 0xBF, return invalid */ | |
| 230 | + if( (*z++&0xC0)!=0x80 ){ | |
| 229 | 231 | return LOOK_INVALID; |
| 230 | 232 | } |
| 231 | 233 | } |
| 232 | 234 | } |
| 233 | 235 | /* advance to the next sequence */ |
| 234 | 236 |
| --- src/lookslike.c | |
| +++ src/lookslike.c | |
| @@ -219,15 +219,17 @@ | |
| 219 | /* if the byte is outside the allowed range for this definition, |
| 220 | * return invalid */ |
| 221 | return LOOK_INVALID; |
| 222 | } |
| 223 | if( len > 2 ){ |
| 224 | if( (*z<0x80) || (*z++>0xBF) ){ |
| 225 | return LOOK_INVALID; |
| 226 | } |
| 227 | if( len > 3 ){ |
| 228 | if( (*z<0x80) || (*z++>0xBF) ){ |
| 229 | return LOOK_INVALID; |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | /* advance to the next sequence */ |
| 234 |
| --- src/lookslike.c | |
| +++ src/lookslike.c | |
| @@ -219,15 +219,17 @@ | |
| 219 | /* if the byte is outside the allowed range for this definition, |
| 220 | * return invalid */ |
| 221 | return LOOK_INVALID; |
| 222 | } |
| 223 | if( len > 2 ){ |
| 224 | /* if the next byte is not between 0x80 and 0xBF, return invalid */ |
| 225 | if( (*z++&0xC0)!=0x80 ){ |
| 226 | return LOOK_INVALID; |
| 227 | } |
| 228 | if( len > 3 ){ |
| 229 | /* if the next byte is not between 0x80 and 0xBF, return invalid */ |
| 230 | if( (*z++&0xC0)!=0x80 ){ |
| 231 | return LOOK_INVALID; |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | /* advance to the next sequence */ |
| 236 |