Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
cf07d3c1
Commit
cf07d3c1
authored
Aug 22, 2019
by
Joshua Haberman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
layout_init() optimization works!
parent
78378dab
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
8 deletions
+57
-8
map.c
ruby/ext/google/protobuf_c/map.c
+1
-1
message.c
ruby/ext/google/protobuf_c/message.c
+0
-2
protobuf.h
ruby/ext/google/protobuf_c/protobuf.h
+5
-1
repeated_field.c
ruby/ext/google/protobuf_c/repeated_field.c
+1
-1
storage.c
ruby/ext/google/protobuf_c/storage.c
+50
-3
No files found.
ruby/ext/google/protobuf_c/map.c
View file @
cf07d3c1
...
...
@@ -495,7 +495,7 @@ VALUE Map_length(VALUE _self) {
return
ULL2NUM
(
upb_strtable_count
(
&
self
->
table
));
}
static
VALUE
Map_new_this_type
(
VALUE
_self
)
{
VALUE
Map_new_this_type
(
VALUE
_self
)
{
Map
*
self
=
ruby_to_Map
(
_self
);
VALUE
new_map
=
Qnil
;
VALUE
key_type
=
fieldtype_to_ruby
(
self
->
key_type
);
...
...
ruby/ext/google/protobuf_c/message.c
View file @
cf07d3c1
...
...
@@ -70,8 +70,6 @@ VALUE Message_alloc(VALUE klass) {
msg
=
(
MessageHeader
*
)
ALLOC_N
(
uint8_t
,
sizeof
(
MessageHeader
)
+
desc
->
layout
->
size
);
memset
(
Message_data
(
msg
),
0
,
desc
->
layout
->
size
);
// We wrap first so that everything in the message object is GC-rooted in case
// a collection happens during object creation in layout_init().
ret
=
TypedData_Wrap_Struct
(
klass
,
&
Message_type
,
msg
);
...
...
ruby/ext/google/protobuf_c/protobuf.h
View file @
cf07d3c1
...
...
@@ -419,6 +419,7 @@ extern VALUE cRepeatedField;
RepeatedField
*
ruby_to_RepeatedField
(
VALUE
value
);
VALUE
RepeatedField_new_this_type
(
VALUE
_self
);
VALUE
RepeatedField_each
(
VALUE
_self
);
VALUE
RepeatedField_index
(
int
argc
,
VALUE
*
argv
,
VALUE
_self
);
void
*
RepeatedField_index_native
(
VALUE
_self
,
int
index
);
...
...
@@ -467,6 +468,7 @@ extern VALUE cMap;
Map
*
ruby_to_Map
(
VALUE
value
);
VALUE
Map_new_this_type
(
VALUE
_self
);
VALUE
Map_each
(
VALUE
_self
);
VALUE
Map_keys
(
VALUE
_self
);
VALUE
Map_values
(
VALUE
_self
);
...
...
@@ -522,11 +524,13 @@ struct MessageLayout {
uint32_t
size
;
uint32_t
value_offset
;
int
value_count
;
int
repeated_count
;
int
map_count
;
};
#define ONEOF_CASE_MASK 0x80000000
MessageLayout
*
create_layout
(
Descriptor
*
desc
);
void
create_layout
(
Descriptor
*
desc
);
void
free_layout
(
MessageLayout
*
layout
);
bool
field_contains_hasbit
(
MessageLayout
*
layout
,
const
upb_fielddef
*
field
);
...
...
ruby/ext/google/protobuf_c/repeated_field.c
View file @
cf07d3c1
...
...
@@ -323,7 +323,7 @@ VALUE RepeatedField_length(VALUE _self) {
return
INT2NUM
(
self
->
size
);
}
static
VALUE
RepeatedField_new_this_type
(
VALUE
_self
)
{
VALUE
RepeatedField_new_this_type
(
VALUE
_self
)
{
RepeatedField
*
self
=
ruby_to_RepeatedField
(
_self
);
VALUE
new_rptfield
=
Qnil
;
VALUE
element_type
=
fieldtype_to_ruby
(
self
->
field_type
);
...
...
ruby/ext/google/protobuf_c/storage.c
View file @
cf07d3c1
...
...
@@ -478,7 +478,7 @@ bool is_value_field(const upb_fielddef* f) {
upb_fielddef_isstring
(
f
);
}
MessageLayout
*
create_layout
(
Descriptor
*
desc
)
{
void
create_layout
(
Descriptor
*
desc
)
{
const
upb_msgdef
*
msgdef
=
desc
->
msgdef
;
MessageLayout
*
layout
=
ALLOC
(
MessageLayout
);
int
nfields
=
upb_msgdef_numfields
(
msgdef
);
...
...
@@ -517,14 +517,49 @@ MessageLayout* create_layout(Descriptor* desc) {
off
=
align_up_to
(
off
,
sizeof
(
VALUE
));
layout
->
value_offset
=
off
;
layout
->
repeated_count
=
0
;
layout
->
map_count
=
0
;
layout
->
value_count
=
0
;
// Place all
(non-oneof) VALUE fields first
.
// Place all
VALUE fields for repeated fields
.
for
(
upb_msg_field_begin
(
&
it
,
msgdef
);
!
upb_msg_field_done
(
&
it
);
upb_msg_field_next
(
&
it
))
{
const
upb_fielddef
*
field
=
upb_msg_iter_field
(
&
it
);
if
(
upb_fielddef_containingoneof
(
field
)
||
!
is_value_field
(
field
))
{
if
(
upb_fielddef_containingoneof
(
field
)
||
!
upb_fielddef_isseq
(
field
)
||
upb_fielddef_ismap
(
field
))
{
continue
;
}
layout
->
fields
[
upb_fielddef_index
(
field
)].
offset
=
off
;
off
+=
sizeof
(
VALUE
);
layout
->
repeated_count
++
;
}
// Place all VALUE fields for map fields.
for
(
upb_msg_field_begin
(
&
it
,
msgdef
);
!
upb_msg_field_done
(
&
it
);
upb_msg_field_next
(
&
it
))
{
const
upb_fielddef
*
field
=
upb_msg_iter_field
(
&
it
);
if
(
upb_fielddef_containingoneof
(
field
)
||
!
upb_fielddef_isseq
(
field
)
||
!
upb_fielddef_ismap
(
field
))
{
continue
;
}
layout
->
fields
[
upb_fielddef_index
(
field
)].
offset
=
off
;
off
+=
sizeof
(
VALUE
);
layout
->
map_count
++
;
}
layout
->
value_count
=
layout
->
repeated_count
+
layout
->
map_count
;
// Next place all other (non-oneof) VALUE fields.
for
(
upb_msg_field_begin
(
&
it
,
msgdef
);
!
upb_msg_field_done
(
&
it
);
upb_msg_field_next
(
&
it
))
{
const
upb_fielddef
*
field
=
upb_msg_iter_field
(
&
it
);
if
(
upb_fielddef_containingoneof
(
field
)
||
!
is_value_field
(
field
)
||
upb_fielddef_isseq
(
field
))
{
continue
;
}
...
...
@@ -909,7 +944,19 @@ void layout_set(MessageLayout* layout,
}
void
layout_init
(
MessageLayout
*
layout
,
void
*
storage
)
{
VALUE
*
value
=
(
VALUE
*
)
CHARPTR_AT
(
storage
,
layout
->
value_offset
);
int
i
;
memcpy
(
storage
,
layout
->
empty_template
,
layout
->
size
);
for
(
i
=
0
;
i
<
layout
->
repeated_count
;
i
++
,
value
++
)
{
*
value
=
RepeatedField_new_this_type
(
*
value
);
}
for
(
i
=
0
;
i
<
layout
->
map_count
;
i
++
,
value
++
)
{
*
value
=
Map_new_this_type
(
*
value
);
}
/*
upb_msg_field_iter it;
for (upb_msg_field_begin(&it, layout->msgdef);
...
...
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