Skip to content

Commit

Permalink
Use reflect for struct string representation
Browse files Browse the repository at this point in the history
Summary: Reduce code bloat -> speed up build.

Reviewed By: leoleovich

Differential Revision: D63625719

fbshipit-source-id: 7ad2495a338756c98c29da95def625c70ce7a16e
  • Loading branch information
echistyakov authored and facebook-github-bot committed Oct 1, 2024
1 parent ab4f277 commit 4d7e521
Show file tree
Hide file tree
Showing 110 changed files with 1,921 additions and 13,305 deletions.
2 changes: 0 additions & 2 deletions thrift/compiler/generate/templates/go/svcs.go.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"context"
"fmt"
"reflect"
"strings"

{{#program:thrift_imports}}
{{program:go_package_alias}} "{{program:go_import_path}}"
Expand All @@ -40,7 +39,6 @@ import (
var _ = context.Background
var _ = fmt.Printf
var _ = reflect.Ptr
var _ = strings.Split
var _ = thrift.ZERO
{{#program:gen_metadata?}}
{{#program:import_metadata_package?}}
Expand Down
2 changes: 0 additions & 2 deletions thrift/compiler/generate/templates/go/types.go.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import (
"fmt"
"reflect"
"strings"

{{#program:thrift_imports}}
{{program:go_package_alias}} "{{program:go_import_path}}"
Expand All @@ -31,7 +30,6 @@ import (
// (needed to ensure safety because of naive import list construction)
var _ = fmt.Printf
var _ = reflect.Ptr
var _ = strings.Split
var _ = thrift.ZERO

{{! Typedefs }}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@
}}
func (x *{{struct:go_name}}) String() string {
{{!
NOTE: Go may invoke String() method on a nil pointer,
so an explicit nil check is required for safety.
}}
if x == nil {
return "<nil>"
}

var sb strings.Builder

sb.WriteString("{{struct:go_name}}({")
{{#struct:fields_sorted}}
sb.WriteString(fmt.Sprintf("{{field:go_name}}:%s{{^last?}} {{/last?}}", x.toString{{field:key_str}}()))
{{/struct:fields_sorted}}
sb.WriteString("})")

return sb.String()
return thrift.StructToString(reflect.ValueOf(x))
}
{{!newline}}
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@
}}{{#struct:fields_sorted}}
{{> types/field_method_read}}

{{/struct:fields_sorted}}{{!
toString method.
}}{{#struct:fields_sorted}}
{{> types/field_method_to_string}}

{{/struct:fields_sorted}}{{!
DefaultGet method.
Expand Down
1 change: 0 additions & 1 deletion thrift/compiler/lib/go/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class codegen_data {
{"thrift", 0},
{"context", 0},
{"fmt", 0},
{"strings", 0},
{"sync", 0},
{"metadata", 0},
{"maps", 0},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"context"
"fmt"
"reflect"
"strings"

thrift "github.com/facebook/fbthrift/thrift/lib/go/thrift/types"
metadata "github.com/facebook/fbthrift/thrift/lib/thrift/metadata"
Expand All @@ -20,7 +19,6 @@ import (
var _ = context.Background
var _ = fmt.Printf
var _ = reflect.Ptr
var _ = strings.Split
var _ = thrift.ZERO
var _ = metadata.GoUnusedProtection__

Expand Down
Loading

0 comments on commit 4d7e521

Please sign in to comment.