[go: nahoru, domu]

Skip to content

Commit

Permalink
Minor fixups to expandArray
Browse files Browse the repository at this point in the history
Find the index keys by comparing the strings directly, so we don't need
to worry about the prefix value altering the regex.
  • Loading branch information
jbardin committed Jan 4, 2017
1 parent 497010c commit 85d8fba
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions flatmap/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package flatmap

import (
"fmt"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -44,16 +43,28 @@ func expandArray(m map[string]string, prefix string) []interface{} {
panic(err)
}

keySet := make(map[int]struct{})
listElementKey := regexp.MustCompile("^" + prefix + "\\.([0-9]+)(?:\\..*)?$")
for key := range m {
if matches := listElementKey.FindStringSubmatch(key); matches != nil {
k, err := strconv.ParseInt(matches[1], 0, 0)
if err != nil {
panic(err)
}
keySet[int(k)] = struct{}{}
keySet := map[int]bool{}
for k := range m {
if !strings.HasPrefix(k, prefix+".") {
continue
}

key := k[len(prefix)+1:]
idx := strings.Index(key, ".")
if idx != -1 {
key = key[:idx]
}

// skip the count value
if key == "#" {
continue
}

k, err := strconv.Atoi(key)
if err != nil {
panic(err)
}
keySet[int(k)] = true
}

keysList := make([]int, 0, num)
Expand Down

0 comments on commit 85d8fba

Please sign in to comment.