Skip to content

Commit ba7318d

Browse files
committed
Improve parsing performance
1 parent 30ad1bb commit ba7318d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

include/tao/json/internal/grammar.hh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,26 @@ namespace tao
112112
using content = object_content;
113113
};
114114

115-
struct value : padr< sor< string, number, object, array, false_, true_, null > > {};
115+
struct sor_value
116+
{
117+
using analyze_t = analysis::generic< analysis::rule_type::SOR, string, number, object, array, false_, true_, null >;
118+
119+
template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States >
120+
static bool match( Input & in, States && ... st )
121+
{
122+
switch( in.peek_char() ) {
123+
case '"': return Control< string >::template match< A, Action, Control >( in, st ... );
124+
case '{': return Control< object >::template match< A, Action, Control >( in, st ... );
125+
case '[': return Control< array >::template match< A, Action, Control >( in, st ... );
126+
case 'n': return Control< null >::template match< A, Action, Control >( in, st ... );
127+
case 't': return Control< true_ >::template match< A, Action, Control >( in, st ... );
128+
case 'f': return Control< false_ >::template match< A, Action, Control >( in, st ... );
129+
default: return Control< number >::template match< A, Action, Control >( in, st ... );
130+
}
131+
}
132+
};
133+
134+
struct value : padr< sor_value > {};
116135
struct array_element : seq< value > {};
117136

118137
struct text : seq< star< ws >, value > {};

0 commit comments

Comments
 (0)