text/flat: FlatText::char_to_byte_index shortcut length_of_char_at if possible
authorJean Privat <jean@pryen.org>
Fri, 4 Mar 2016 02:40:57 +0000 (21:40 -0500)
committerJean Privat <jean@pryen.org>
Fri, 4 Mar 2016 02:59:15 +0000 (21:59 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/core/text/flat.nit

index 200fdcf..2615304 100644 (file)
@@ -55,7 +55,11 @@ redef class FlatText
                var its = _items
 
                if dpos == 1 then
-                       b += _items.length_of_char_at(b)
+                       if its[b] & 0x80u8 == 0x00u8 then
+                               b += 1
+                       else
+                               b += its.length_of_char_at(b)
+                       end
                        _bytepos = b
                        _position = index
                        return b