6
6
#include " JSONStack.h"
7
7
namespace JSON
8
8
{
9
+ #if defined(_JS_VALUE) || (_DOM_VALUE)
10
+ #error "Something went wrong!"
11
+ #endif
12
+
13
+ #define _JS_VALUE tempValues[0 ]
14
+ #define _DOM_VALUE tempValues[1 ]
15
+
9
16
bool StrictEqualsObjectComparer::Equals (Js::Var x, Js::Var y)
10
17
{
11
18
return JSONStack::Equals (x,y);
12
19
}
13
20
14
- JSONStack::JSONStack (ArenaAllocator *allocator, Js::ScriptContext *context) : jsObjectStack(allocator), domObjectStack(nullptr ), alloc(allocator), scriptContext(context)
21
+ JSONStack::JSONStack (ArenaAllocator *allocator, Js::ScriptContext *context)
22
+ : jsObjectStack(allocator), domObjectStack(nullptr ),
23
+ alloc (allocator), scriptContext(context)
15
24
{
25
+ // most of the time, the size of the stack is 1 object.
26
+ // use direct member instead of expensive Push / Pop / Has
27
+ _JS_VALUE = nullptr ;
28
+ _DOM_VALUE = nullptr ;
16
29
}
17
30
18
31
bool JSONStack::Equals (Js::Var x, Js::Var y)
@@ -24,10 +37,18 @@ namespace JSON
24
37
{
25
38
if (bJsObject)
26
39
{
40
+ if (_JS_VALUE)
41
+ {
42
+ return (data == _JS_VALUE);
43
+ }
27
44
return jsObjectStack.Has (data);
28
45
}
29
46
else if (domObjectStack)
30
47
{
48
+ if (_DOM_VALUE)
49
+ {
50
+ return (data == _DOM_VALUE);
51
+ }
31
52
return domObjectStack->Contains (data);
32
53
}
33
54
return false ;
@@ -37,22 +58,68 @@ namespace JSON
37
58
{
38
59
if (bJsObject)
39
60
{
40
- return jsObjectStack.Push (data);
61
+ bool result = true ;
62
+ if (_JS_VALUE)
63
+ {
64
+ jsObjectStack.Push (_JS_VALUE);
65
+ _JS_VALUE = nullptr ;
66
+ }
67
+
68
+ if (jsObjectStack.Count ())
69
+ {
70
+ result = jsObjectStack.Push (data);
71
+ }
72
+ else
73
+ {
74
+ _JS_VALUE = data;
75
+ }
76
+
77
+ return result;
41
78
}
79
+
42
80
EnsuresDomObjectStack ();
43
- domObjectStack->Add (data);
81
+
82
+ if (_DOM_VALUE)
83
+ {
84
+ domObjectStack->Add (_DOM_VALUE);
85
+ _DOM_VALUE = nullptr ;
86
+ }
87
+
88
+ if (domObjectStack->Count ())
89
+ {
90
+ domObjectStack->Add (data);
91
+ }
92
+ else
93
+ {
94
+ _DOM_VALUE = data;
95
+ }
44
96
return true ;
45
97
}
46
98
47
99
void JSONStack::Pop (bool bJsObject)
48
100
{
49
101
if (bJsObject)
50
102
{
51
- jsObjectStack.Pop ();
103
+ if (_JS_VALUE)
104
+ {
105
+ _JS_VALUE = nullptr ;
106
+ }
107
+ else
108
+ {
109
+ jsObjectStack.Pop ();
110
+ }
52
111
return ;
53
112
}
54
113
AssertMsg (domObjectStack != NULL , " Misaligned pop" );
55
- domObjectStack->RemoveAtEnd ();
114
+
115
+ if (_DOM_VALUE)
116
+ {
117
+ _DOM_VALUE = nullptr ;
118
+ }
119
+ else
120
+ {
121
+ domObjectStack->RemoveAtEnd ();
122
+ }
56
123
}
57
124
58
125
void JSONStack::EnsuresDomObjectStack (void )
@@ -62,4 +129,7 @@ namespace JSON
62
129
domObjectStack = DOMObjectStack::New (alloc);
63
130
}
64
131
}
65
- }// namespace JSON
132
+ } // namespace JSON
133
+
134
+ #undef _JS_VALUE
135
+ #undef _DOM_VALUE
0 commit comments