diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-03-06 13:39:53 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-03-06 13:39:53 +0100 |
commit | 083d4eb0362152c38c6824bbeb0d785cd13c2b67 (patch) | |
tree | f8548ba67c3d61e2c4affd0a345c9864bf0c7972 /src/patharray.js | |
parent | 250f97ff2c615ad08c15e902bbed4cb9cf3fdcd9 (diff) | |
download | svg.js-083d4eb0362152c38c6824bbeb0d785cd13c2b67.tar.gz svg.js-083d4eb0362152c38c6824bbeb0d785cd13c2b67.zip |
speed up path parsing for most cases
added test, added pathArray speed bench
Diffstat (limited to 'src/patharray.js')
-rw-r--r-- | src/patharray.js | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/src/patharray.js b/src/patharray.js index 366729e..385342f 100644 --- a/src/patharray.js +++ b/src/patharray.js @@ -172,23 +172,11 @@ SVG.extend(SVG.PathArray, { if(typeof array == 'string'){ array = array - .replace(SVG.regex.negExp, 'X') // replace all negative exponents with certain char + .replace(SVG.regex.numbersWithDots, pathRegReplace) // convert 45.123.123 to 45.123 .123 .replace(SVG.regex.pathLetters, ' $& ') // put some room between letters and numbers - .replace(SVG.regex.hyphen, ' -') // add space before hyphen - .replace(SVG.regex.comma, ' ') // unify all spaces - .replace(SVG.regex.X, 'e-') // add back the expoent + .replace(SVG.regex.hyphen, '$1 -') // add space before hyphen .trim() // trim - .split(SVG.regex.whitespaces) // split into array - - // at this place there could be parts like ['3.124.854.32'] because we could not determine the point as seperator till now - // we fix this elements in the next loop - for(i = array.length; --i;){ - if(array[i].indexOf('.') != array[i].lastIndexOf('.')){ - var split = array[i].split('.') // split at the point - var first = [split.shift(), split.shift()].join('.') // join the first number together - array.splice.apply(array, [i, 1].concat(first, split.map(function(el){ return '.'+el }))) // add first and all other entries back to array - } - } + .split(SVG.regex.delimiter) // split into array }else{ array = array.reduce(function(prev, curr){ |