thriftrw / thriftrw-go

A Thrift encoding code generator and library for Go
MIT License
100 stars 53 forks source link

optimize String() on a typedef if the underlying type is a string #554

Closed kishoresenji closed 2 years ago

kishoresenji commented 2 years ago

If the underlying type for a defined type is a string, then the Stringer interface implementation can be optimized by returning the string after type conversion.

type UUID string
func (v UUID) String() string {
        x := (string)(v)
        return fmt.Sprint(x)
 }

to

func (v UUID) String() string {
        x := (string)(v)
        return x
 }
CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

codecov[bot] commented 2 years ago

Codecov Report

Merging #554 (9f3eb52) into dev (944fb9f) will increase coverage by 0.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #554      +/-   ##
==========================================
+ Coverage   68.00%   68.01%   +0.01%     
==========================================
  Files         139      139              
  Lines       23729    23737       +8     
==========================================
+ Hits        16137    16145       +8     
  Misses       4537     4537              
  Partials     3055     3055              
Impacted Files Coverage Δ
gen/generator.go 67.23% <100.00%> (+0.18%) :arrow_up:
gen/internal/tests/services/services.go 61.30% <100.00%> (ø)
gen/internal/tests/typedefs/typedefs.go 68.11% <100.00%> (ø)
gen/internal/tests/uuid_conflict/uuid_conflict.go 63.44% <100.00%> (ø)
gen/type.go 83.50% <100.00%> (+0.52%) :arrow_up:
gen/typedef.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 944fb9f...9f3eb52. Read the comment docs.