Browse Source

improve performance of json validation

Kolja Strohm 7 months ago
parent
commit
01cea70976
6 changed files with 106 additions and 86 deletions
  1. 22 22
      DX12PixelShader.h
  2. 17 17
      DX12VertexShader.h
  3. 27 9
      JSON.cpp
  4. 2 0
      JSON.h
  5. 23 23
      UIPixelShader.h
  6. 15 15
      UIVertexShader.h

+ 22 - 22
DX12PixelShader.h

@@ -92,10 +92,10 @@ ret
 
 const BYTE DX12PixelShaderBytes[] =
 {
-     68,  88,  66,  67,  87, 150, 
-    218, 241,  91, 175, 101,  96, 
-    231, 218,  37, 203,  53, 250, 
-    161, 119,   1,   0,   0,   0, 
+     68,  88,  66,  67,  77,  82, 
+    194, 213,   8,  69,  52,  93, 
+    183, 250,  94, 100, 251, 175, 
+     11, 229,   1,   0,   0,   0, 
     184,  91,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
      36,   2,   0,   0, 188,   2, 
@@ -763,11 +763,11 @@ const BYTE DX12PixelShaderBytes[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0, 148,  46, 
-     49,   1, 188, 137, 224, 100, 
-      1,   0,   0,   0, 164, 230, 
-    191, 253, 229, 164,  16,  71, 
-    138, 212,  70,  57, 113,  52, 
-      7, 224,   0,   0,   0,   0, 
+     49,   1,  37, 248, 242, 100, 
+      1,   0,   0,   0, 121, 110, 
+    225, 205,  49, 208, 173,  70, 
+    156, 218, 100, 199, 135, 105, 
+     65, 108,   0,   0,   0,   0, 
       0,   0,   0,   0,   1,   0, 
       0,   0,   1,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -938,10 +938,10 @@ const BYTE DX12PixelShaderBytes[] =
       3,   0, 242,  56,   1,   0, 
      43, 236,   3,   0,  28,  19, 
       2,   0,  65,  36,   1,   0, 
-    236, 179,   1,   0,  46,  81, 
-      1,   0, 125,  10,   2,   0, 
-    125, 181,   2,   0, 100,  27, 
-      1,   0, 193,  33,   3,   0, 
+    236, 179,   1,   0, 174,  44, 
+      3,   0, 125,  10,   2,   0, 
+    125, 181,   2,   0, 252, 225, 
+      2,   0, 193,  33,   3,   0, 
      65, 185,   2,   0, 140, 239, 
       1,   0, 246,  49,   0,   0, 
     213, 255,   0,   0,  46, 248, 
@@ -1788,7 +1788,7 @@ const BYTE DX12PixelShaderBytes[] =
     117, 114, 101,  50,  68,  32, 
     115, 104,  97, 100,  27, 226, 
      48,   1, 128,   0,   0,   0, 
-      9, 131, 236, 157, 126, 210, 
+     66, 237, 151,   2, 123, 221, 
     217,   1,   1,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -2348,14 +2348,14 @@ const BYTE DX12PixelShaderBytes[] =
       0,   0,  23,   0,   1,   0, 
       5,  16,   0,   0,  14,   0, 
      23,  21,   0,  16,   0,   0, 
-      3,   2,  16,   7,   0,   0, 
+      3,   2, 240, 101,   0,   0, 
     242, 241,  10,   0,  24,  21, 
       8,  16,   0,   0,   1,   0, 
       1,   0,  10,   0,  24,  21, 
       9,  16,   0,   0,   1,   0, 
       0,   2,  14,   0,  23,  21, 
       0,   0,   0,   0,  10,   2, 
-     16,   7,   0,   0, 242, 241, 
+    240, 101,   0,   0, 242, 241, 
      10,   0,  24,  21,  11,  16, 
       0,   0,   1,   0,   1,   0, 
      10,   0,  24,  21,  12,  16, 
@@ -3408,11 +3408,11 @@ const BYTE DX12PixelShaderBytes[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
-    148,  46,  49,   1, 188, 137, 
-    224, 100,   1,   0,   0,   0, 
-    164, 230, 191, 253, 229, 164, 
-     16,  71, 138, 212,  70,  57, 
-    113,  52,   7, 224, 128,   0, 
+    148,  46,  49,   1,  37, 248, 
+    242, 100,   1,   0,   0,   0, 
+    121, 110, 225, 205,  49, 208, 
+    173,  70, 156, 218, 100, 199, 
+    135, 105,  65, 108, 128,   0, 
       0,   0,  47,  76, 105, 110, 
     107,  73, 110, 102, 111,   0, 
      47, 110,  97, 109, 101, 115, 
@@ -3512,7 +3512,7 @@ const BYTE DX12PixelShaderBytes[] =
       0,   0,   2,   0,   9,   0, 
     220,   4,   0,   0,   0,   0, 
       0,   0, 156,   1,   0,   0, 
-      1,   0, 185, 166,   0,   0, 
+      1,   0, 227,  42,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0, 109,  97, 
     105, 110,   0, 110, 111, 110, 

+ 17 - 17
DX12VertexShader.h

@@ -131,10 +131,10 @@ ret
 
 const BYTE DX12VertexShaderBytes[] =
 {
-     68,  88,  66,  67,  21, 227, 
-    118,  99,  54, 105, 241, 147, 
-    153,  71, 150, 173, 127,  75, 
-    140,  28,   1,   0,   0,   0, 
+     68,  88,  66,  67, 227, 161, 
+    106, 168, 213,  74, 153, 171, 
+    208,  72, 247, 139,  92,  47, 
+     24,  32,   1,   0,   0,   0, 
     144,  78,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
     124,   2,   0,   0,  52,   3, 
@@ -923,11 +923,11 @@ const BYTE DX12VertexShaderBytes[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
-    148,  46,  49,   1, 188, 137, 
-    224, 100,   1,   0,   0,   0, 
-    152,  48, 225,  12, 118, 105, 
-     95,  65, 161, 174, 168, 171, 
-     66,  24, 218, 144,   0,   0, 
+    148,  46,  49,   1,  37, 248, 
+    242, 100,   1,   0,   0,   0, 
+     36, 144, 209, 113, 172, 241, 
+     34,  67, 129, 147,  52,  44, 
+    136, 154,  75, 177,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       1,   0,   0,   0,   1,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -1103,7 +1103,7 @@ const BYTE DX12VertexShaderBytes[] =
       0,   0, 103, 159,   1,   0, 
     179, 120,   1,   0, 238,  97, 
       2,   0,  90,  28,   0,   0, 
-    144, 227,   1,   0,  53, 174, 
+    219,  57,   2,   0,  53, 174, 
       3,   0, 206,  21,   0,   0, 
     193, 205,   3,   0, 207, 193, 
       1,   0,  62,   3,   3,   0, 
@@ -1607,7 +1607,7 @@ const BYTE DX12VertexShaderBytes[] =
      97, 109, 101, 114,  97,  13, 
      10, 115, 116, 114,  27, 226, 
      48,   1, 128,   0,   0,   0, 
-     20, 178,   3, 158, 126, 210, 
+     27,  92, 174,   2, 123, 221, 
     217,   1,   1,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -2125,7 +2125,7 @@ const BYTE DX12VertexShaderBytes[] =
      24,  21,  12,  16,   0,   0, 
       1,   0,   1,   0,  14,   0, 
      23,  21,  13,  16,   0,   0, 
-     36,   2, 224, 146,   0,   0, 
+     36,   2, 176,  76,   0,   0, 
     242, 241,  10,   0,  24,  21, 
      14,  16,   0,   0,   1,   0, 
       0,   2,  18,   0,  22,  21, 
@@ -3057,10 +3057,10 @@ const BYTE DX12VertexShaderBytes[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0, 148,  46,  49,   1, 
-    188, 137, 224, 100,   1,   0, 
-      0,   0, 152,  48, 225,  12, 
-    118, 105,  95,  65, 161, 174, 
-    168, 171,  66,  24, 218, 144, 
+     37, 248, 242, 100,   1,   0, 
+      0,   0,  36, 144, 209, 113, 
+    172, 241,  34,  67, 129, 147, 
+     52,  44, 136, 154,  75, 177, 
     129,   0,   0,   0,  47,  76, 
     105, 110, 107,  73, 110, 102, 
     111,   0,  47, 110,  97, 109, 
@@ -3160,7 +3160,7 @@ const BYTE DX12VertexShaderBytes[] =
       0,   0,   0,   0,   2,   0, 
       9,   0, 156,   5,   0,   0, 
       0,   0,   0,   0, 236,   2, 
-      0,   0,   1,   0, 184, 146, 
+      0,   0,   1,   0, 107,  76, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
     109,  97, 105, 110,   0, 110, 

+ 27 - 9
JSON.cpp

@@ -256,7 +256,12 @@ Text JSONArray::toString() const
 
 JSONValue* JSONArray::clone() const
 {
-    return new JSONArray(toString());
+    JSONArray* arr = new JSONArray();
+    for (JSONValue* value : *this)
+    {
+        arr->addValue(value->clone());
+    }
+    return arr;
 }
 
 #pragma endregion Content
@@ -414,7 +419,14 @@ Text JSONObject::toString() const
 
 JSONValue* JSONObject::clone() const
 {
-    return new JSONObject(toString());
+    JSONObject* obj = new JSONObject();
+    auto field = fields->begin();
+    auto value = values->begin();
+    for (; field && value; field++, value++)
+    {
+        obj->addValue(field.val(), value->clone());
+    }
+    return obj;
 }
 
 #pragma endregion Content
@@ -1238,7 +1250,16 @@ void Framework::JSON::Validator::JSONValidValue::addBasePath(Text basePath)
 JSONValidator::JSONValidator(XML::Element* constraints)
     : ReferenceCounter(),
       constraints(constraints)
-{}
+{
+    for (XML::Element* e : constraints->select()
+                               .selectAllElements()
+                               .whereNameEquals("object")
+                               .whereAttributeExists("id"))
+    {
+        Framework::Text id = e->getAttributeValue("id");
+        typeConstraints.set(id, id.getLength(), e);
+    }
+}
 
 JSONValidator::~JSONValidator()
 {
@@ -1489,13 +1510,10 @@ JSONValidationResult* JSONValidator::validate(
         if (zConstraints->getName().istGleich("objectRef"))
         {
             Text id = zConstraints->getAttributeValue("ref");
-            XML::Editor editor = constraints->select()
-                                     .selectAllElements()
-                                     .whereNameEquals("object")
-                                     .whereAttributeEquals("id", id);
-            if (editor.getSize())
+            XML::Element* e = typeConstraints.get(id, id.getLength());
+            if (e)
             {
-                zConstraints = editor.begin().val();
+                zConstraints = e;
             }
         }
         if (!zConstraints->getName().istGleich("object"))

+ 2 - 0
JSON.h

@@ -7,6 +7,7 @@
 #include "Text.h"
 #include "Writer.h"
 #include "XML.h"
+#include "Trie.h"
 
 namespace Framework
 {
@@ -414,6 +415,7 @@ namespace Framework
             {
             private:
                 XML::Element* constraints;
+                Trie<XML::Element*> typeConstraints;
 
             public:
                 __declspec(dllexport) JSONValidator(XML::Element* constraints);

+ 23 - 23
UIPixelShader.h

@@ -352,10 +352,10 @@ ret
 
 const BYTE UIPixelShader[] =
 {
-     68,  88,  66,  67,  76,  12, 
-    125, 142,  62, 252, 125, 113, 
-    173, 246, 194, 216, 149,  45, 
-     48,  41,   1,   0,   0,   0, 
+     68,  88,  66,  67,  30,  31, 
+    208, 123, 120, 206,  31, 151, 
+    181, 214,  32,  58, 179, 110, 
+    141, 183,   1,   0,   0,   0, 
      12, 134,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
     140,   6,   0,   0,  28,   7, 
@@ -1805,11 +1805,11 @@ const BYTE UIPixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0, 148,  46, 
-     49,   1, 188, 137, 224, 100, 
-      1,   0,   0,   0,  50, 192, 
-    233, 209,  88,  60, 185,  73, 
-    157,  16, 243,  30,  20,  90, 
-    193, 110,   0,   0,   0,   0, 
+     49,   1,  38, 248, 242, 100, 
+      1,   0,   0,   0, 231,  80, 
+    145,  26,  53,  12, 175,  77, 
+    168,  96,  76, 138,  89,  20, 
+     83,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   1,   0, 
       0,   0,   1,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -1980,10 +1980,10 @@ const BYTE UIPixelShader[] =
       3,   0, 242,  56,   1,   0, 
      43, 236,   3,   0,  28,  19, 
       2,   0,  65,  36,   1,   0, 
-    236, 179,   1,   0,  46,  81, 
-      1,   0, 125,  10,   2,   0, 
-    125, 181,   2,   0, 100,  27, 
-      1,   0, 193,  33,   3,   0, 
+    236, 179,   1,   0, 174,  44, 
+      3,   0, 125,  10,   2,   0, 
+    125, 181,   2,   0, 252, 225, 
+      2,   0, 193,  33,   3,   0, 
      65, 185,   2,   0,   9, 241, 
       2,   0, 146, 230,   3,   0, 
     125, 218,   1,   0, 118,  19, 
@@ -3000,8 +3000,8 @@ const BYTE UIPixelShader[] =
      84, 101, 120, 116, 117, 114, 
     101,  50,  68,  32, 115, 104, 
      97, 100,  27, 226,  48,   1, 
-    128,   0,   0,   0, 180, 232, 
-     22, 158, 126, 210, 217,   1, 
+    128,   0,   0,   0, 222, 140, 
+    192,   2, 123, 221, 217,   1, 
       1,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -4243,14 +4243,14 @@ const BYTE UIPixelShader[] =
       6,  16,   0,   0,  23,   0, 
       1,   0,   5,  16,   0,   0, 
      14,   0,  23,  21,   0,  16, 
-      0,   0,   3,   2,  16,   7, 
+      0,   0,   3,   2, 240, 101, 
       0,   0, 242, 241,  10,   0, 
      24,  21,   8,  16,   0,   0, 
       1,   0,   1,   0,  10,   0, 
      24,  21,   9,  16,   0,   0, 
       1,   0,   0,   2,  14,   0, 
      23,  21,   0,   0,   0,   0, 
-     10,   2,  16,   7,   0,   0, 
+     10,   2, 240, 101,   0,   0, 
     242, 241,  10,   0,  24,  21, 
      11,  16,   0,   0,   1,   0, 
       1,   0,  10,   0,  24,  21, 
@@ -5474,11 +5474,11 @@ const BYTE UIPixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
-    148,  46,  49,   1, 188, 137, 
-    224, 100,   1,   0,   0,   0, 
-     50, 192, 233, 209,  88,  60, 
-    185,  73, 157,  16, 243,  30, 
-     20,  90, 193, 110, 128,   0, 
+    148,  46,  49,   1,  38, 248, 
+    242, 100,   1,   0,   0,   0, 
+    231,  80, 145,  26,  53,  12, 
+    175,  77, 168,  96,  76, 138, 
+     89,  20,  83,   0, 128,   0, 
       0,   0,  47,  76, 105, 110, 
     107,  73, 110, 102, 111,   0, 
      47, 110,  97, 109, 101, 115, 
@@ -5578,7 +5578,7 @@ const BYTE UIPixelShader[] =
       0,   0,   2,   0,   9,   0, 
     204,   8,   0,   0,   0,   0, 
       0,   0, 164,  14,   0,   0, 
-      1,   0,  40, 172,   0,   0, 
+      1,   0, 140, 121,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,  84, 101, 
     120, 116, 117, 114, 101,  80, 

+ 15 - 15
UIVertexShader.h

@@ -121,10 +121,10 @@ ret
 
 const BYTE UIVertexShader[] =
 {
-     68,  88,  66,  67,  15, 181, 
-     91,  50, 181,  37, 127, 220, 
-    254,  85, 210, 142,  71, 248, 
-    110, 136,   1,   0,   0,   0, 
+     68,  88,  66,  67,  83,  70, 
+     82,  21, 215, 163, 110, 205, 
+    115, 166,  36,  27,  32,  16, 
+     86, 243,   1,   0,   0,   0, 
     204,  77,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
      20,   2,   0,   0, 204,   2, 
@@ -881,10 +881,10 @@ const BYTE UIVertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0, 148,  46,  49,   1, 
-    188, 137, 224, 100,   1,   0, 
-      0,   0, 137, 197,  97,  47, 
-    110, 106,  72,  69, 185,  42, 
-     78,  62, 145,  16,   6, 136, 
+     38, 248, 242, 100,   1,   0, 
+      0,   0, 168, 240, 211, 221, 
+    164,  69, 173,  65, 150, 144, 
+     59, 238,  74,  51, 160,  62, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   1,   0,   0,   0, 
       1,   0,   0,   0,   0,   0, 
@@ -1564,8 +1564,8 @@ const BYTE UIVertexShader[] =
      13,  10,  47,  47,  32,  84, 
      89,  80,  69,  68,  69,  70, 
      27, 226,  48,   1, 128,   0, 
-      0,   0,   4, 157,  54, 158, 
-    126, 210, 217,   1,   1,   0, 
+      0,   0, 232, 182, 220,   2, 
+    123, 221, 217,   1,   1,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -2929,10 +2929,10 @@ const BYTE UIVertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0, 148,  46,  49,   1, 
-    188, 137, 224, 100,   1,   0, 
-      0,   0, 137, 197,  97,  47, 
-    110, 106,  72,  69, 185,  42, 
-     78,  62, 145,  16,   6, 136, 
+     38, 248, 242, 100,   1,   0, 
+      0,   0, 168, 240, 211, 221, 
+    164,  69, 173,  65, 150, 144, 
+     59, 238,  74,  51, 160,  62, 
     129,   0,   0,   0,  47,  76, 
     105, 110, 107,  73, 110, 102, 
     111,   0,  47, 110,  97, 109, 
@@ -3032,7 +3032,7 @@ const BYTE UIVertexShader[] =
       0,   0,   0,   0,   2,   0, 
       9,   0, 104,   5,   0,   0, 
       0,   0,   0,   0, 236,   2, 
-      0,   0,   1,   0, 249, 116, 
+      0,   0,   1,   0, 202, 145, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
      84, 101, 120, 116, 117, 114,