Skip to content

Commit 1f2a266

Browse files
committed
Codegen: convert Arc<Box<T>> to Arc<T>
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 <xynnn@linux.alibaba.com>
1 parent 152ac12 commit 1f2a266

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

compiler/src/codegen.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'a> MethodGen<'a> {
145145
"}",
146146
|w| {
147147
w.write_line(&format!(
148-
"service: Arc<Box<dyn {} + Send + Sync>>,",
148+
"service: Arc<dyn {} + Send + Sync>,",
149149
self.service_name
150150
));
151151
},
@@ -558,7 +558,7 @@ impl<'a> ServiceGen<'a> {
558558
fn write_sync_server_create(&self, w: &mut CodeWriter) {
559559
let method_handler_name = "::ttrpc::MethodHandler";
560560
let s = format!(
561-
"create_{}(service: Arc<Box<dyn {} + Send + Sync>>) -> HashMap<String, Box<dyn {} + Send + Sync>>",
561+
"create_{}(service: Arc<dyn {} + Send + Sync>) -> HashMap<String, Box<dyn {} + Send + Sync>>",
562562
to_snake_case(&self.service_name()),
563563
self.service_name(),
564564
method_handler_name,
@@ -577,7 +577,7 @@ impl<'a> ServiceGen<'a> {
577577

578578
fn write_async_server_create(&self, w: &mut CodeWriter) {
579579
let s = format!(
580-
"create_{}(service: Arc<Box<dyn {} + Send + Sync>>) -> HashMap<String, {}>",
580+
"create_{}(service: Arc<dyn {} + Send + Sync>) -> HashMap<String, {}>",
581581
to_snake_case(&self.service_name()),
582582
self.service_name(),
583583
"::ttrpc::r#async::Service"
@@ -642,7 +642,6 @@ fn write_generated_common(w: &mut CodeWriter) {
642642
w.write_line("#![cfg_attr(rustfmt, rustfmt_skip)]");
643643
w.write_line("#![allow(unknown_lints)]");
644644
w.write_line("#![allow(clipto_camel_casepy)]");
645-
w.write_line("#![allow(box_pointers)]");
646645
w.write_line("#![allow(dead_code)]");
647646
w.write_line("#![allow(missing_docs)]");
648647
w.write_line("#![allow(non_camel_case_types)]");

0 commit comments

Comments
 (0)