]> mj.ucw.cz Git - libucw.git/commitdiff
Mempools: Optimize mp_append_utf8_32()
authorMartin Mares <mj@ucw.cz>
Fri, 17 Jul 2015 14:10:31 +0000 (16:10 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 17 Jul 2015 14:10:31 +0000 (16:10 +0200)
ucw/mempool-str.c
ucw/unicode.h

index 0edfe26474ef4ba42e7a33d472ed4895e1a68d3e..48c60f41f2996042876fb933a4ab9fedf5671cda 100644 (file)
@@ -97,7 +97,7 @@ mp_str_from_mem(struct mempool *a, const void *mem, size_t len)
 
 void *mp_append_utf8_32(struct mempool *pool, void *p, uint c)
 {
-  p = mp_spread(pool, p, utf8_space(c));
+  p = mp_spread(pool, p, UTF8_MAX_LEN);
   return utf8_32_put(p, c);
 }
 
index dd3d35b0a52e88705372f28348c58c790aea3269..4ec1c6b2ca8aa010733f0a09d46824ec2ae10f25 100644 (file)
@@ -248,6 +248,9 @@ static inline uint utf8_encoding_len(uint c)
   return 6;
 }
 
+/** Maximum number of bytes an UTF-8 character can have. **/
+#define UTF8_MAX_LEN 6
+
 /**
  * Encode an UTF-16LE character from the range `[0, 0xD7FF]` or `[0xE000,0x11FFFF]`;
  * up to 4 bytes needed.