From 5582e13c1d704a42d55d4cc2434d79e615d119b1 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Mon, 15 Jun 2015 11:14:13 +0100 Subject: [PATCH] maximum/minimum keywords optimized --- lib/compile/rules/maximum.dot.js | 5 +++-- lib/compile/rules/minItems.dot.js | 2 +- lib/compile/rules/minimum.dot.js | 5 +++-- package.json | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/compile/rules/maximum.dot.js b/lib/compile/rules/maximum.dot.js index 90e929b..2fea90b 100644 --- a/lib/compile/rules/maximum.dot.js +++ b/lib/compile/rules/maximum.dot.js @@ -3,9 +3,10 @@ {{ var $exclusive = it.schema.exclusiveMaximum === true - , $op = $exclusive ? '<' : '<='; + , $op = $exclusive ? '<' : '<=' /*used in error*/ + , $notOp = $exclusive ? '>=' : '>'; }} -if (! ({{=$data}} {{=$op}} {{=$schema}}) ) { +if ({{=$data}} {{=$notOp}} {{=$schema}}) { {{# def.error:'maximum' }} } {{? $breakOnError }} else { {{?}} diff --git a/lib/compile/rules/minItems.dot.js b/lib/compile/rules/minItems.dot.js index 38825f4..8e1081d 100644 --- a/lib/compile/rules/minItems.dot.js +++ b/lib/compile/rules/minItems.dot.js @@ -1,6 +1,6 @@ {{# def.definitions }} {{# def.setup:'minItems' }} -if ({{=$data}}.length < {{=$schema}}) { +if ({{=$data}}.length < {{=$schema}}) { {{# def.error:'minItems' }} } {{? $breakOnError }} else { {{?}} diff --git a/lib/compile/rules/minimum.dot.js b/lib/compile/rules/minimum.dot.js index bf7cda2..5ce1028 100644 --- a/lib/compile/rules/minimum.dot.js +++ b/lib/compile/rules/minimum.dot.js @@ -3,9 +3,10 @@ {{ var $exclusive = it.schema.exclusiveMinimum === true - , $op = $exclusive ? '>' : '>='; + , $op = $exclusive ? '>' : '>=' /*used in error*/ + , $notOp = $exclusive ? '<=' : '<'; }} -if (!( {{=$data}} {{=$op}} {{=$schema}} )) { +if ({{=$data}} {{=$notOp}} {{=$schema}}) { {{# def.error:'minimum' }} } {{? $breakOnError }} else { {{?}} diff --git a/package.json b/package.json index b5bbd7c..ed60bc3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "0.4.6", + "version": "0.4.7", "description": "Another JSON schema Validator", "main": "lib/ajv.js", "scripts": {