Fossil SCM

A little bit faster, by only accessing *z once and using bit-operations in stead of comparisions.

jan.nijtmans 2016-06-16 08:04 invalid_utf8_table
Commit f246ea43130abcd5244754c717cb8127aecfb611
1 file changed +5 -3
+5 -3
--- src/lookslike.c
+++ src/lookslike.c
@@ -219,15 +219,17 @@
219219
/* if the byte is outside the allowed range for this definition,
220220
* return invalid */
221221
return LOOK_INVALID;
222222
}
223223
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;
226227
}
227228
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 ){
229231
return LOOK_INVALID;
230232
}
231233
}
232234
}
233235
/* advance to the next sequence */
234236
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button