Permalink
Browse files

[unoptimized] added code that works for reference

  • Loading branch information...
1 parent e4c921c commit da0d9397c28ec7debcd0fe62adec3cf0d92d70e9 @dscape committed Dec 21, 2011
Showing with 17 additions and 27 deletions.
  1. +12 −22 clarinet.js
  2. +3 −3 package.json
  3. +2 −2 test/bench.html
View
@@ -374,30 +374,20 @@ if(typeof FastList === 'function') {
continue;
case S.STRING:
- // thanks thejh, this is an about 50% performance improvment.
- var starti = i
- , consecutive_slashes = 0
- ;
- while (c) {
- // if it seems like end of string
- // and we found slashes before
- // and those slashes an even number
- // -> this is not an escape its the end of the string
- if (c === '"' &&
- (consecutive_slashes === 0 || consecutive_slashes%2 ===0)) {
- parser.state = parser.stack.pop() || S.VALUE;
- break;
+ if (c === '"') parser.state = parser.stack.pop() || S.VALUE;
+ else if (c === '\\') parser.state = S.BACKSLASH;
+ else parser.textNode += c;
+ continue;
+
+ case S.BACKSLASH:
+ if (c==='\\' || c === '"') parser.textNode += c;
+ else {
+ if(p==='\\') {
+ parser.textNode += '\\';
}
- if (c === '\\') consecutive_slashes++;
- else consecutive_slashes = 0;
- parser.position ++;
- if (c === "\n") {
- parser.line ++;
- parser.column = 0;
- } else parser.column ++;
- c = chunk.charAt(i++);
+ parser.textNode += c;
}
- parser.textNode += chunk.substring(starti, i-1);
+ parser.state = S.STRING;
continue;
case S.TRUE:
View
@@ -1,8 +1,8 @@
{ "name" : "clarinet"
, "description" :
- "SAX-Like evented streaming JSON parser in JavaScript browser and node"
+ "SAX based evented streaming JSON parser in JavaScript (browser and node)"
, "author" : "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com/)"
-, "version" : "0.5.0"
+, "version" : "0.5.1"
, "main" : "./clarinet.js"
, "homepage" : "https://github.com/dscape/clarinet"
, "repository" :
@@ -12,7 +12,7 @@
, "bugs" : "http://github.com/dscape/clarinet/issues"
, "keywords" :
["sax", "json", "parser", "stream", "streaming", "event"
- , "events", "emitter", "async", "streamer"]
+ , "events", "emitter", "async", "streamer", "browser"]
, "devDependencies" :
{ "mocha": "0.3.6", "should": "0.3.2", "underscore": "1.2.3" }
, "scripts" :
View
@@ -8,9 +8,9 @@
<script src="basic.js"></script>
<script>
onload = function(){
- var string = JSON.stringify(BASIC)
+ var string = JSON.stringify(TWITTER)
, p = clarinet.parser()
- , max = 1000
+ , max = 1
, iters = 5
;

0 comments on commit da0d939

Please sign in to comment.