Casts aclitem earl to avoid O(2n)
This commit is contained in:
+12
-12
@@ -36,62 +36,62 @@ func TestEscapeAclItem(t *testing.T) {
|
|||||||
func TestParseAclItemArray(t *testing.T) {
|
func TestParseAclItemArray(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
input string
|
input string
|
||||||
expected []string
|
expected []AclItem
|
||||||
errMsg string
|
errMsg string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"",
|
"",
|
||||||
[]string{},
|
[]AclItem{},
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"one",
|
"one",
|
||||||
[]string{"one"},
|
[]AclItem{"one"},
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`"one"`,
|
`"one"`,
|
||||||
[]string{"one"},
|
[]AclItem{"one"},
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"one,two,three",
|
"one,two,three",
|
||||||
[]string{"one", "two", "three"},
|
[]AclItem{"one", "two", "three"},
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`"one","two","three"`,
|
`"one","two","three"`,
|
||||||
[]string{"one", "two", "three"},
|
[]AclItem{"one", "two", "three"},
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`"one",two,"three"`,
|
`"one",two,"three"`,
|
||||||
[]string{"one", "two", "three"},
|
[]AclItem{"one", "two", "three"},
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`one,two,"three"`,
|
`one,two,"three"`,
|
||||||
[]string{"one", "two", "three"},
|
[]AclItem{"one", "two", "three"},
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`"one","two",three`,
|
`"one","two",three`,
|
||||||
[]string{"one", "two", "three"},
|
[]AclItem{"one", "two", "three"},
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`"one","t w o",three`,
|
`"one","t w o",three`,
|
||||||
[]string{"one", "t w o", "three"},
|
[]AclItem{"one", "t w o", "three"},
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`"one","t, w o\"\}\\",three`,
|
`"one","t, w o\"\}\\",three`,
|
||||||
[]string{"one", `t, w o"}\`, "three"},
|
[]AclItem{"one", `t, w o"}\`, "three"},
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`"one","two",three"`,
|
`"one","two",three"`,
|
||||||
[]string{"one", "two", `three"`},
|
[]AclItem{"one", "two", `three"`},
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3057,11 +3057,11 @@ func encodeAclItemSlice(w *WriteBuf, oid Oid, aclitems []AclItem) error {
|
|||||||
|
|
||||||
// parseAclItemArray parses the textual representation
|
// parseAclItemArray parses the textual representation
|
||||||
// of the aclitem[] type.
|
// of the aclitem[] type.
|
||||||
func parseAclItemArray(arr string) ([]string, error) {
|
func parseAclItemArray(arr string) ([]AclItem, error) {
|
||||||
r := strings.NewReader(arr)
|
r := strings.NewReader(arr)
|
||||||
// Difficult to guess a performant initial capacity for a slice of
|
// Difficult to guess a performant initial capacity for a slice of
|
||||||
// aclitems, but let's go with 5.
|
// aclitems, but let's go with 5.
|
||||||
vals := make([]string, 0, 5)
|
vals := make([]AclItem, 0, 5)
|
||||||
// A single value
|
// A single value
|
||||||
vlu := ""
|
vlu := ""
|
||||||
for {
|
for {
|
||||||
@@ -3094,13 +3094,13 @@ func parseAclItemArray(arr string) ([]string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
// This error was expected and is OK.
|
// This error was expected and is OK.
|
||||||
vals = append(vals, vlu)
|
vals = append(vals, AclItem(vlu))
|
||||||
return vals, nil
|
return vals, nil
|
||||||
}
|
}
|
||||||
// This error was not expected.
|
// This error was not expected.
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
vals = append(vals, vlu)
|
vals = append(vals, AclItem(vlu))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3192,13 +3192,7 @@ func decodeAclItemArray(vr *ValueReader) []AclItem {
|
|||||||
vr.Fatal(ProtocolError(err.Error()))
|
vr.Fatal(ProtocolError(err.Error()))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
return strs
|
||||||
// cast strings into AclItems before returning
|
|
||||||
aclitems := make([]AclItem, len(strs))
|
|
||||||
for i := range aclitems {
|
|
||||||
aclitems[i] = AclItem(strs[i])
|
|
||||||
}
|
|
||||||
return aclitems
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeStringSlice(w *WriteBuf, oid Oid, slice []string) error {
|
func encodeStringSlice(w *WriteBuf, oid Oid, slice []string) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user