Skip to content

Commit

Permalink
Codegen: convert Arc<Box<T>> to Arc<T>
Browse files Browse the repository at this point in the history
This commit changes the generated ttrpc server from Arc<Box<T>>
to Arc<T>. This helps the type conversion and also avoids extra runtime
cost caused by double pointer.

Fixes #234

Signed-off-by: Xynnn007 <[email protected]>
  • Loading branch information
Xynnn007 committed Aug 20, 2024
1 parent 152ac12 commit 022108f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compiler/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a> MethodGen<'a> {
"}",
|w| {
w.write_line(&format!(
"service: Arc<Box<dyn {} + Send + Sync>>,",
"service: Arc<dyn {} + Send + Sync>,",
self.service_name
));
},
Expand Down Expand Up @@ -558,7 +558,7 @@ impl<'a> ServiceGen<'a> {
fn write_sync_server_create(&self, w: &mut CodeWriter) {
let method_handler_name = "::ttrpc::MethodHandler";
let s = format!(
"create_{}(service: Arc<Box<dyn {} + Send + Sync>>) -> HashMap<String, Box<dyn {} + Send + Sync>>",
"create_{}(service: Arc<dyn {} + Send + Sync>) -> HashMap<String, Box<dyn {} + Send + Sync>>",
to_snake_case(&self.service_name()),
self.service_name(),
method_handler_name,
Expand All @@ -577,7 +577,7 @@ impl<'a> ServiceGen<'a> {

fn write_async_server_create(&self, w: &mut CodeWriter) {
let s = format!(
"create_{}(service: Arc<Box<dyn {} + Send + Sync>>) -> HashMap<String, {}>",
"create_{}(service: Arc<dyn {} + Send + Sync>) -> HashMap<String, {}>",
to_snake_case(&self.service_name()),
self.service_name(),
"::ttrpc::r#async::Service"
Expand Down

0 comments on commit 022108f

Please sign in to comment.