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 Sep 9, 2024
1 parent 152ac12 commit 1f2a266
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 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 Expand Up @@ -642,7 +642,6 @@ fn write_generated_common(w: &mut CodeWriter) {
w.write_line("#![cfg_attr(rustfmt, rustfmt_skip)]");
w.write_line("#![allow(unknown_lints)]");
w.write_line("#![allow(clipto_camel_casepy)]");
w.write_line("#![allow(box_pointers)]");
w.write_line("#![allow(dead_code)]");
w.write_line("#![allow(missing_docs)]");
w.write_line("#![allow(non_camel_case_types)]");
Expand Down

0 comments on commit 1f2a266

Please sign in to comment.