Skip to content

Commit

Permalink
Pre-compute prefix when array is not flat
Browse files Browse the repository at this point in the history
  • Loading branch information
kgeckhart committed Dec 4, 2024
1 parent 9a211f9 commit 4cd0fa3
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions aws/protocol/query/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,8 @@ type Array struct {
// keys for each element in the list. For example, an entry might have the
// key "ParentStructure.ListName.member.MemberName.1".
//
// While this is currently represented as a string that gets added to, it
// could also be represented as a stack that only gets condensed into a
// string when a finalized key is created. This could potentially reduce
// allocations.
// When the array is not flat the prefix will contain the memberName otherwise the memberName is ignored
prefix string
// Whether the list is flat or not. A list that is not flat will produce the
// following entry to the url.Values for a given entry:
// ListName.MemberName.1=value
// A list that is flat will produce the following:
// ListName.1=value
flat bool
// The location name of the member. In most cases this should be "member".
memberName string
// Elements are stored in values, so we keep track of the list size here.
size int32
// Empty lists are encoded as "<prefix>=", if we add a value later we will
Expand All @@ -45,11 +34,13 @@ func newArray(values url.Values, prefix string, flat bool, memberName string) *A
emptyValue := newValue(values, prefix, flat)
emptyValue.String("")

if !flat {
prefix = prefix + keySeparator + memberName
}

return &Array{
values: values,
prefix: prefix,
flat: flat,
memberName: memberName,
emptyValue: emptyValue,
}
}
Expand All @@ -63,10 +54,6 @@ func (a *Array) Value() Value {

// Query lists start a 1, so adjust the size first
a.size++
prefix := a.prefix
if !a.flat {
prefix = fmt.Sprintf("%s.%s", prefix, a.memberName)
}
// Lists can't have flat members
return newValue(a.values, fmt.Sprintf("%s.%d", prefix, a.size), false)
return newValue(a.values, fmt.Sprintf("%s.%d", a.prefix, a.size), false)
}

0 comments on commit 4cd0fa3

Please sign in to comment.