Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
51dbfebf
Commit
51dbfebf
authored
Dec 27, 2019
by
Vicențiu Ciorbaru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Eliminate duplicate code by refactoring into a function
parent
5e125b5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
44 deletions
+36
-44
sql/mysql_json.cc
sql/mysql_json.cc
+36
-44
No files found.
sql/mysql_json.cc
View file @
51dbfebf
...
...
@@ -334,6 +334,32 @@ static bool parse_mysql_scalar(String *buffer, size_t value_json_type,
}
}
static
bool
read_mysql_scalar_or_value
(
String
*
buffer
,
const
char
*
data
,
size_t
len
,
size_t
value_type_offset
,
bool
large
,
size_t
depth
)
{
/* Get the type of the value stored at the key. */
const
JSONB_TYPES
value_type
=
static_cast
<
JSONB_TYPES
>
(
data
[
value_type_offset
]);
if
(
type_is_stored_inline
(
value_type
,
large
))
{
const
size_t
value_start
=
value_type_offset
+
1
;
if
(
parse_mysql_scalar
(
buffer
,
value_type
,
data
+
value_start
,
len
-
value_start
))
return
true
;
}
else
{
const
size_t
value_start
=
read_offset_or_size
(
data
+
value_type_offset
+
1
,
large
);
if
(
parse_mysql_json_value
(
buffer
,
value_type
,
data
+
value_start
,
len
-
value_start
,
depth
))
return
true
;
}
return
false
;
}
static
bool
parse_array_or_object
(
String
*
buffer
,
const
char
*
data
,
size_t
len
,
bool
handle_as_object
,
bool
large
,
...
...
@@ -394,12 +420,8 @@ static bool parse_array_or_object(String *buffer, const char *data, size_t len,
data
+
key_offset
+
offset_size
,
false
);
const
size_t
value_type_offset
=
2
*
offset_size
+
key_size
(
large
)
*
element_count
+
value_size
(
large
)
*
i
;
/* Get the type of the value stored at the key. */
const
JSONB_TYPES
value_type
=
static_cast
<
JSONB_TYPES
>
(
data
[
value_type_offset
]);
element_count
*
key_size
(
large
)
+
i
*
value_size
(
large
);
/* First print the key. */
if
(
buffer
->
append
(
'"'
)
||
...
...
@@ -409,54 +431,24 @@ static bool parse_array_or_object(String *buffer, const char *data, size_t len,
return
true
;
}
if
(
type_is_stored_inline
(
value_type
,
large
))
{
if
(
parse_mysql_scalar
(
buffer
,
value_type
,
data
+
value_type_offset
+
1
,
bytes
-
value_type_offset
-
1
))
return
true
;
}
else
{
const
size_t
val_start_offset
=
read_offset_or_size
(
data
+
value_type_offset
+
1
,
large
);
if
(
parse_mysql_json_value
(
buffer
,
value_type
,
data
+
val_start_offset
,
bytes
-
val_start_offset
,
depth
))
return
true
;
}
if
(
read_mysql_scalar_or_value
(
buffer
,
data
,
bytes
,
value_type_offset
,
large
,
depth
))
return
true
;
if
(
i
!=
element_count
-
1
&&
buffer
->
append
(
", "
))
return
true
;
}
else
{
/*
Arrays do not have the keys vector and it
'
s associated data.
Arrays do not have the keys vector and its associated data.
We jump straight to reading values.
*/
const
size_t
value_type_offset
=
2
*
offset_size
+
value_size
(
large
)
*
i
;
const
JSONB_TYPES
value_type
=
static_cast
<
JSONB_TYPES
>
(
data
[
value_type_offset
]);
if
(
type_is_stored_inline
(
value_type
,
large
))
{
const
size_t
value_start
=
value_type_offset
+
1
;
if
(
parse_mysql_scalar
(
buffer
,
value_type
,
data
+
value_start
,
bytes
-
value_start
))
return
true
;
}
else
{
/*
Regular values have their position marked after the type.
A regular value can be either a scalar, an array or another JSON
object.
*/
const
size_t
value_start
=
read_offset_or_size
(
data
+
value_type_offset
+
1
,
large
);
if
(
parse_mysql_json_value
(
buffer
,
value_type
,
data
+
value_start
,
bytes
-
value_start
,
depth
))
return
true
;
}
if
(
read_mysql_scalar_or_value
(
buffer
,
data
,
bytes
,
value_type_offset
,
large
,
depth
))
return
true
;
if
(
i
!=
element_count
-
1
&&
buffer
->
append
(
", "
))
return
true
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment