Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
4abd86c7
Commit
4abd86c7
authored
Nov 8, 2019
by
Hannah Shi
Browse files
Options
Downloads
Patches
Plain Diff
reduce 3 times memcpy of message to 1 time only.
parent
ab7e5e8d
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/php/ext/grpc/byte_buffer.c
+30
-0
30 additions, 0 deletions
src/php/ext/grpc/byte_buffer.c
src/php/ext/grpc/byte_buffer.h
+4
-0
4 additions, 0 deletions
src/php/ext/grpc/byte_buffer.h
src/php/ext/grpc/call.c
+23
-0
23 additions, 0 deletions
src/php/ext/grpc/call.c
with
57 additions
and
0 deletions
src/php/ext/grpc/byte_buffer.c
+
30
−
0
View file @
4abd86c7
...
...
@@ -31,6 +31,8 @@ grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length) {
return
buffer
;
}
#if PHP_MAJOR_VERSION < 7
void
byte_buffer_to_string
(
grpc_byte_buffer
*
buffer
,
char
**
out_string
,
size_t
*
out_length
)
{
grpc_byte_buffer_reader
reader
;
...
...
@@ -50,3 +52,31 @@ void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string,
*
out_string
=
string
;
*
out_length
=
length
;
}
#else
zend_string
*
byte_buffer_to_zend_string
(
grpc_byte_buffer
*
buffer
)
{
grpc_byte_buffer_reader
reader
;
if
(
buffer
==
NULL
||
!
grpc_byte_buffer_reader_init
(
&
reader
,
buffer
))
{
/* TODO(dgq): distinguish between the error cases. */
return
NULL
;
}
const
size_t
length
=
grpc_byte_buffer_length
(
reader
.
buffer_out
);
zend_string
*
zstr
=
zend_string_alloc
(
length
,
0
);
char
*
buf
=
ZSTR_VAL
(
zstr
);
grpc_slice
next
;
while
(
grpc_byte_buffer_reader_next
(
&
reader
,
&
next
)
!=
0
)
{
const
size_t
next_len
=
GRPC_SLICE_LENGTH
(
next
);
memcpy
(
buf
,
GRPC_SLICE_START_PTR
(
next
),
next_len
);
buf
+=
next_len
;
grpc_slice_unref
(
next
);
}
*
buf
=
'\0'
;
return
zstr
;
}
#endif // PHP_MAJOR_VERSION < 7
This diff is collapsed.
Click to expand it.
src/php/ext/grpc/byte_buffer.h
+
4
−
0
View file @
4abd86c7
...
...
@@ -23,7 +23,11 @@
grpc_byte_buffer
*
string_to_byte_buffer
(
char
*
string
,
size_t
length
);
#if PHP_MAJOR_VERSION < 7
void
byte_buffer_to_string
(
grpc_byte_buffer
*
buffer
,
char
**
out_string
,
size_t
*
out_length
);
#else
zend_string
*
byte_buffer_to_zend_string
(
grpc_byte_buffer
*
buffer
);
#endif // PHP_MAJOR_VERSION < 7
#endif
/* NET_GRPC_PHP_GRPC_BYTE_BUFFER_H_ */
This diff is collapsed.
Click to expand it.
src/php/ext/grpc/call.c
+
23
−
0
View file @
4abd86c7
...
...
@@ -294,8 +294,13 @@ PHP_METHOD(Call, startBatch) {
grpc_byte_buffer
*
message
;
int
cancelled
;
grpc_call_error
error
;
#if PHP_MAJOR_VERSION < 7
char
*
message_str
;
size_t
message_len
;
#else
zend_string
*
zmessage
=
NULL
;
#endif // PHP_MAJOR_VERSION < 7
grpc_metadata_array_init
(
&
metadata
);
grpc_metadata_array_init
(
&
trailing_metadata
);
...
...
@@ -483,12 +488,28 @@ PHP_METHOD(Call, startBatch) {
PHP_GRPC_DELREF
(
array
);
break
;
case
GRPC_OP_RECV_MESSAGE
:
#if PHP_MAJOR_VERSION < 7
byte_buffer_to_string
(
message
,
&
message_str
,
&
message_len
);
#else
zmessage
=
byte_buffer_to_zend_string
(
message
);
#endif // PHP_MAJOR_VERSION < 7
#if PHP_MAJOR_VERSION < 7
if
(
message_str
==
NULL
)
{
#else
if
(
zmessage
==
NULL
)
{
#endif // PHP_MAJOR_VERSION < 7
add_property_null
(
result
,
"message"
);
}
else
{
#if PHP_MAJOR_VERSION < 7
php_grpc_add_property_stringl
(
result
,
"message"
,
message_str
,
message_len
,
false
);
#else
zval
zmessage_val
;
ZVAL_NEW_STR
(
&
zmessage_val
,
zmessage
);
add_property_zval
(
result
,
"message"
,
&
zmessage_val
);
zval_ptr_dtor
(
&
zmessage_val
);
#endif // PHP_MAJOR_VERSION < 7
}
break
;
case
GRPC_OP_RECV_STATUS_ON_CLIENT
:
...
...
@@ -537,7 +558,9 @@ cleanup:
}
if
(
ops
[
i
].
op
==
GRPC_OP_RECV_MESSAGE
)
{
grpc_byte_buffer_destroy
(
message
);
#if PHP_MAJOR_VERSION < 7
PHP_GRPC_FREE_STD_ZVAL
(
message_str
);
#endif // PHP_MAJOR_VERSION < 7
}
}
RETURN_DESTROY_ZVAL
(
result
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment