Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: impl/memory/testing_utils_test.go

Issue 2342063003: Differentiate between single- and multi- props. (Closed)
Patch Set: Slice is now always a clone. This is marginally worse performance, but a much safer UI. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « impl/memory/race_test.go ('k') | impl/prod/everything_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/testing_utils_test.go
diff --git a/impl/memory/testing_utils_test.go b/impl/memory/testing_utils_test.go
index 66447d078c180cc78b2f96c71ce0b566f9e7e579..6a249167fb8c9b975a1da767b20c0e1129db4666 100644
--- a/impl/memory/testing_utils_test.go
+++ b/impl/memory/testing_utils_test.go
@@ -23,36 +23,63 @@ func init() {
var nextMarker = "NEXT MARKER"
var Next = &nextMarker
-// Use like:
+var multiMarker = "MULTI MARKER"
+var Multi = &multiMarker
+
+// If you want an entry that is single to be treated as multi-, prepend it
+// with Multi. Terminate each set of property tokens with Next.
// pmap(
// "prop", "val", 0, 100, Next,
// "other", "val", 0, 100, Next,
+// "name", Multi, "value", Next,
// )
//
+//
+//
func pmap(stuff ...interface{}) ds.PropertyMap {
ret := ds.PropertyMap{}
- nom := func() interface{} {
- if len(stuff) > 0 {
- ret := stuff[0]
- stuff = stuff[1:]
- return ret
+ nom := func() (name string, toks []interface{}, multi bool) {
+ var i int
+
+ for i = 0; i < len(stuff); i++ {
+ e := stuff[i]
+ switch {
+ case e == Next:
+ stuff = stuff[i+1:]
+ return
+ case e == Multi:
+ multi = true
+ case i == 0:
+ name = e.(string)
+ default:
+ toks = append(toks, e)
+ }
}
- return nil
+
+ stuff = nil
+ return
}
for len(stuff) > 0 {
- pname := nom().(string)
+ pname, toks, multi := nom()
+
+ var mp func(interface{}) ds.Property
if pname[0] == '$' || (strings.HasPrefix(pname, "__") && strings.HasSuffix(pname, "__")) {
- for len(stuff) > 0 && stuff[0] != Next {
- ret[pname] = append(ret[pname], propNI(nom()))
- }
+ mp = propNI
+ } else {
+ mp = prop
+ }
+
+ if len(toks) == 1 && !multi {
+ ret[pname] = mp(toks[0])
} else {
- for len(stuff) > 0 && stuff[0] != Next {
- ret[pname] = append(ret[pname], prop(nom()))
+ pslice := make(ds.PropertySlice, len(toks))
+ for i, tok := range toks {
+ pslice[i] = mp(tok)
}
+ ret[pname] = pslice
}
- nom()
}
return ret
« no previous file with comments | « impl/memory/race_test.go ('k') | impl/prod/everything_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698