Browse files

Fix the fix

  • Loading branch information...
1 parent 8fd84e6 commit 59f51d2d1b0b8d390fc4b14dbbd60e189b9280d3 @flori committed Mar 21, 2012
Showing with 6 additions and 21 deletions.
  1. +6 −21 ext/json/ext/generator/generator.c
View
27 ext/json/ext/generator/generator.c
@@ -854,27 +854,12 @@ static VALUE cState_partial_generate(VALUE self, VALUE obj)
static int isArrayOrObject(VALUE string)
{
- char c, *q, *p = RSTRING_PTR(string), *pend = p + RSTRING_LEN(string);
-
- while (p < pend) {
- if (isspace(*p)) {
- p++;
- continue;
- }
- if (*p == '[') c = ']';
- else if (*p == '{') c = '}';
- else return 0;
- q = pend - 1;
- while (q > p) {
- if (isspace(*q)) {
- q--;
- continue;
- }
- if (*q == c) return 1;
- }
- return 0;
- }
- return 0;
+ long string_len = RSTRING_LEN(string);
+ char c, *p = RSTRING_PTR(string), *q = p + string_len - 1;
+ if (string_len < 2) return 0;
+ for (; p < q && isspace(*p); p++);
+ for (; q > p && isspace(*q); q--);
+ return *p == '[' && *q == ']' || *p == '{' && *q == '}';
}
/*

0 comments on commit 59f51d2

Please sign in to comment.