From 882696f858a764ea9354763370e10aa15d31d1b4 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Tue, 15 Oct 2019 00:04:45 -0400 Subject: Slight performance improvement & refactoring Signed-off-by: Dave Henderson --- conv/conv.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'conv') diff --git a/conv/conv.go b/conv/conv.go index cd9cb771..20435f93 100644 --- a/conv/conv.go +++ b/conv/conv.go @@ -7,6 +7,7 @@ import ( "strconv" "strings" + iconv "github.com/hairyhenderson/gomplate/internal/conv" "github.com/pkg/errors" ) @@ -82,7 +83,7 @@ func Join(in interface{}, sep string) (out string, err error) { var a []interface{} a, ok = in.([]interface{}) if !ok { - a, err = interfaceSlice(in) + a, err = iconv.InterfaceSlice(in) if err != nil { return "", errors.Wrap(err, "Input to Join must be an array") } @@ -99,21 +100,6 @@ func Join(in interface{}, sep string) (out string, err error) { return "", errors.New("Input to Join must be an array") } -func interfaceSlice(slice interface{}) ([]interface{}, error) { - s := reflect.ValueOf(slice) - kind := s.Kind() - switch kind { - case reflect.Slice, reflect.Array: - ret := make([]interface{}, s.Len()) - for i := 0; i < s.Len(); i++ { - ret[i] = s.Index(i).Interface() - } - return ret, nil - default: - return nil, errors.Errorf("expected an array or slice, but got a %T", s) - } -} - // Has determines whether or not a given object has a property with the given key func Has(in interface{}, key interface{}) bool { av := reflect.ValueOf(in) -- cgit v1.2.3