Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prost-build: optimise derived prost::Name
When deriving prost::Name, prost-bulid generates the following code for full_name and type_url methods: fn full_name() -> ::prost::alloc::string::String { ::prost::alloc::format!( "some.package.{0}", Self::NAME ) } fn type_url() -> ::prost::alloc::string::String { ::prost::alloc::format!( "example.com/{0}", Self::full_name() ) } With those definitions, type_url: - allocates a new temporary string, - formats text into that string, - allocates another string, - and once again formats text into that string. Most of those operations can be done at build time with only a single string allocation being necessary in type_url method. Change the generated code such that no formatting happens at run time and no temporary strings are allocated in type_url, specifically: fn full_name() -> ::prost::alloc::string::String { "some.package.MessageName".into() } fn type_url() -> ::prost::alloc::string::String { "example.com/some.package.MessageName" } Furthermore, unconditionally derive type_url even if no domain is specified such that default definition (which uses temporary strings and formatting) isn’t used.
- Loading branch information