diff options
author | Adrian Johnson <ajohnson@redneon.com> | 2009-09-28 19:14:46 +0930 |
---|---|---|
committer | Adrian Johnson <ajohnson@redneon.com> | 2009-10-29 22:05:19 +1030 |
commit | 600dd833983bd85bf8aea487393ce156abb622bd (patch) | |
tree | 6009453b80ba5f2f955fa07d39d34f4354f9548c | |
parent | f571356d346565cae34f08d12c584c4bd40921d6 (diff) |
Provide a builtin implementation of isspace() and isdigit()
The glibc versions are slow in utf8 locales.
-rw-r--r-- | src/cairo-output-stream.c | 7 | ||||
-rw-r--r-- | src/cairo-pdf-operators.c | 6 | ||||
-rw-r--r-- | src/cairo-type1-subset.c | 16 | ||||
-rw-r--r-- | src/cairoint.h | 16 |
4 files changed, 28 insertions, 17 deletions
diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c index 71154339..20f676c9 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 22c0a88d..7b88092e 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 fe74dc6c..8619e3e2 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 d03fd87a..5912173f 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" |