Skip to content

Commit

Permalink
Remove unnecessary pointer dereference in pdata (#5909)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan <[email protected]>

Signed-off-by: Bogdan <[email protected]>
  • Loading branch information
bogdandrutu authored Aug 15, 2022
1 parent 1f2fa1b commit df91e0e
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 211 deletions.
28 changes: 14 additions & 14 deletions pdata/internal/cmd/pdatagen/internal/base_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

const accessorSliceTemplate = `// ${fieldName} returns the ${originFieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${returnType} {
return new${returnType}(&(*ms.orig).${originFieldName})
return new${returnType}(&ms.orig.${originFieldName})
}`

const accessorsSliceTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) {
Expand All @@ -34,7 +34,7 @@ const accessorsSliceTestTemplate = `func Test${structName}_${fieldName}(t *testi

const accessorsMessageValueTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${returnType} {
return new${returnType}(&(*ms.orig).${originFieldName})
return new${returnType}(&ms.orig.${originFieldName})
}`

const accessorsMessageValueTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) {
Expand All @@ -45,12 +45,12 @@ const accessorsMessageValueTestTemplate = `func Test${structName}_${fieldName}(t

const accessorsPrimitiveTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${returnType} {
return (*ms.orig).${originFieldName}
return ms.orig.${originFieldName}
}
// Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) Set${fieldName}(v ${returnType}) {
(*ms.orig).${originFieldName} = v
ms.orig.${originFieldName} = v
}`

const copyToPrimitiveSliceTestTemplate = ` if len(ms.orig.${originFieldName}) == 0 {
Expand All @@ -63,12 +63,12 @@ const copyToPrimitiveSliceTestTemplate = ` if len(ms.orig.${originFieldName}) ==

const accessorsPrimitiveSliceTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${returnType} {
return ${returnType}{value: (*ms.orig).${originFieldName}}
return ${returnType}{value: ms.orig.${originFieldName}}
}
// Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) Set${fieldName}(v ${returnType}) {
(*ms.orig).${originFieldName} = v.value
ms.orig.${originFieldName} = v.value
}`

const oneOfTypeAccessorHeaderTemplate = `// ${originFieldName}Type returns the type of the ${lowerOriginFieldName} for this ${structName}.
Expand Down Expand Up @@ -117,12 +117,12 @@ const copyToValueOneOfMessageTemplate = ` case ${typeName}:

const accessorsOneOfPrimitiveTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${returnType} {
return (*ms.orig).Get${originFieldName}()
return ms.orig.Get${originFieldName}()
}
// Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) Set${fieldName}(v ${returnType}) {
(*ms.orig).${originOneOfFieldName} = &${originStructType}{
ms.orig.${originOneOfFieldName} = &${originStructType}{
${originFieldName}: v,
}
}`
Expand All @@ -137,27 +137,27 @@ const accessorsPrimitiveTestTemplate = `func Test${structName}_${fieldName}(t *t

const accessorsPrimitiveTypedTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${returnType} {
return ${returnType}((*ms.orig).${originFieldName})
return ${returnType}(ms.orig.${originFieldName})
}
// Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) Set${fieldName}(v ${returnType}) {
(*ms.orig).${originFieldName} = ${rawType}(v)
ms.orig.${originFieldName} = ${rawType}(v)
}`

const accessorsPrimitiveStructTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${returnType} {
return ${returnType}{orig: ((*ms.orig).${originFieldName})}
return ${returnType}{orig: (ms.orig.${originFieldName})}
}
// Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) Set${fieldName}(v ${returnType}) {
(*ms.orig).${originFieldName} = v.orig
ms.orig.${originFieldName} = v.orig
}`

const accessorsOptionalPrimitiveValueTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${returnType} {
return (*ms.orig).Get${fieldName}()
return ms.orig.Get${fieldName}()
}
// Has${fieldName} returns true if the ${structName} contains a
// ${fieldName} value, false otherwise.
Expand All @@ -166,7 +166,7 @@ func (ms ${structName}) Has${fieldName}() bool {
}
// Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) Set${fieldName}(v ${returnType}) {
(*ms.orig).${fieldName}_ = &${originStructType}{${fieldName}: v}
ms.orig.${fieldName}_ = &${originStructType}{${fieldName}: v}
}`

type baseField interface {
Expand Down
14 changes: 7 additions & 7 deletions pdata/internal/generated_common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 25 additions & 25 deletions pdata/internal/generated_plog.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit df91e0e

Please sign in to comment.