[cairo-commit] src/cairoint.h src/cairo-output-stream.c src/cairo-pdf-operators.c src/cairo-type1-subset.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Thu Oct 29 04:42:56 PDT 2009


 src/cairo-output-stream.c |    7 +++----
 src/cairo-pdf-operators.c |    6 ++----
 src/cairo-type1-subset.c  |   16 +++++++---------
 src/cairoint.h            |   16 ++++++++++++++++
 4 files changed, 28 insertions(+), 17 deletions(-)

New commits:
commit 600dd833983bd85bf8aea487393ce156abb622bd
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Mon Sep 28 19:14:46 2009 +0930

    Provide a builtin implementation of isspace() and isdigit()
    
    The glibc versions are slow in utf8 locales.

diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c
index 7115433..20f676c 100644
--- a/src/cairo-output-stream.c
+++ b/src/cairo-output-stream.c
@@ -41,7 +41,6 @@
 
 #include <stdio.h>
 #include <locale.h>
-#include <ctype.h>
 #include <errno.h>
 
 /* Numbers printed with %f are printed with this number of significant
@@ -341,7 +340,7 @@ _cairo_dtostr (char *buffer, size_t size, double d, cairo_bool_t limited_precisi
 	    if (*p == '+' || *p == '-')
 		p++;
 
-	    while (isdigit (*p))
+	    while (_cairo_isdigit (*p))
 		p++;
 
 	    if (strncmp (p, decimal_point, decimal_point_len) == 0)
@@ -362,7 +361,7 @@ _cairo_dtostr (char *buffer, size_t size, double d, cairo_bool_t limited_precisi
     if (*p == '+' || *p == '-')
 	p++;
 
-    while (isdigit (*p))
+    while (_cairo_isdigit (*p))
 	p++;
 
     if (strncmp (p, decimal_point, decimal_point_len) == 0) {
@@ -434,7 +433,7 @@ _cairo_output_stream_vprintf (cairo_output_stream_t *stream,
 	    f++;
         }
 
-	while (isdigit (*f))
+	while (_cairo_isdigit (*f))
 	    f++;
 
 	length_modifier = 0;
diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index 22c0a88..7b88092 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -48,8 +48,6 @@
 #include "cairo-output-stream-private.h"
 #include "cairo-scaled-font-subsets-private.h"
 
-#include <ctype.h>
-
 static cairo_status_t
 _cairo_pdf_operators_end_text (cairo_pdf_operators_t    *pdf_operators);
 
@@ -180,7 +178,7 @@ _count_word_up_to (const unsigned char *s, int length)
     int word = 0;
 
     while (length--) {
-	if (! (isspace (*s) || *s == '<')) {
+	if (! (_cairo_isspace (*s) || *s == '<')) {
 	    s++;
 	    word++;
 	} else {
@@ -239,7 +237,7 @@ _word_wrap_stream_write (cairo_output_stream_t  *base,
 	    length--;
 	    _cairo_output_stream_printf (stream->output, ">");
 	    stream->column++;
-	} else if (isspace (*data)) {
+	} else if (_cairo_isspace (*data)) {
 	    newline =  (*data == '\n' || *data == '\r');
 	    if (! newline && stream->column >= stream->max_column) {
 		_cairo_output_stream_printf (stream->output, "\n");
diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c
index fe74dc6..8619e3e 100644
--- a/src/cairo-type1-subset.c
+++ b/src/cairo-type1-subset.c
@@ -58,8 +58,6 @@
 #include FT_OUTLINE_H
 #include FT_TYPE1_TABLES_H
 
-#include <ctype.h>
-
 typedef struct _cairo_type1_font_subset {
     cairo_scaled_font_subset_t *scaled_font_subset;
 
@@ -295,8 +293,8 @@ cairo_type1_font_erase_dict_key (cairo_type1_font_subset_t *font,
 	    p = start + strlen(key);
 	    /* skip integers or array of integers */
 	    while (p < segment_end &&
-		   (isspace(*p) ||
-		    isdigit(*p) ||
+		   (_cairo_isspace(*p) ||
+		    _cairo_isdigit(*p) ||
 		    *p == '[' ||
 		    *p == ']'))
 	    {
@@ -354,7 +352,7 @@ cairo_type1_font_subset_write_header (cairo_type1_font_subset_t *font,
     start = find_token (font->header_segment, segment_end, "/UniqueID");
     if (start) {
 	start += 9;
-	while (start < segment_end && isspace (*start))
+	while (start < segment_end && _cairo_isspace (*start))
 	    start++;
 	if (start + 5 < segment_end && memcmp(start, "known", 5) == 0) {
 	    _cairo_output_stream_write (font->output, font->header_segment,
@@ -474,7 +472,7 @@ cairo_type1_font_subset_decrypt_eexec_segment (cairo_type1_font_subset_t *font)
     while (in < end) {
 	if (font->eexec_segment_is_ascii) {
 	    c = *in++;
-	    if (isspace (c))
+	    if (_cairo_isspace (c))
 		continue;
 	    c = (hex_to_int (c) << 4) | hex_to_int (*in++);
 	} else {
@@ -510,10 +508,10 @@ cairo_type1_font_subset_decrypt_eexec_segment (cairo_type1_font_subset_t *font)
 static const char *
 skip_token (const char *p, const char *end)
 {
-    while (p < end && isspace(*p))
+    while (p < end && _cairo_isspace(*p))
 	p++;
 
-    while (p < end && !isspace(*p))
+    while (p < end && !_cairo_isspace(*p))
 	p++;
 
     if (p == end)
@@ -969,7 +967,7 @@ cairo_type1_font_subset_for_each_glyph (cairo_type1_font_subset_t *font,
 
 	/* Skip binary data and |- or ND token. */
 	p = skip_token (charstring + charstring_length, dict_end);
-	while (p < dict_end && isspace(*p))
+	while (p < dict_end && _cairo_isspace(*p))
 	    p++;
 
 	/* In case any of the skip_token() calls above reached EOF, p will
diff --git a/src/cairoint.h b/src/cairoint.h
index d03fd87..5912173 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -229,6 +229,22 @@ be32_to_cpu(uint32_t v)
 
 #endif
 
+
+/* The glibc versions of ispace() and isdigit() are slow in UTF-8 locales.
+ */
+
+static inline int cairo_const
+_cairo_isspace (int c)
+{
+    return (c == 0x20 || (c >= 0x09 && c <= 0x0d));
+}
+
+static inline int cairo_const
+_cairo_isdigit (int c)
+{
+    return (c >= '0' && c <= '9');
+}
+
 #include "cairo-types-private.h"
 #include "cairo-cache-private.h"
 #include "cairo-reference-count-private.h"


More information about the cairo-commit mailing list