Browse Source

fix some issues in generating gast path code for slices and maps via gen-fast-path.go.

These include:

- int32/uint32 type was not encoded property.
- use a slice (not map) so as to guarantee sequence of map value types.
- also, generate code for maps with value types of int32, uint, uint32
Ugorji Nwoke 11 years ago
parent
commit
dca82994cf
2 changed files with 419 additions and 256 deletions
  1. 400 246
      codec/fast-path.go
  2. 19 10
      codec/gen-fast-path.go

File diff suppressed because it is too large
+ 400 - 246
codec/fast-path.go


+ 19 - 10
codec/gen-fast-path.go

@@ -212,9 +212,9 @@ type genInfo struct {
 
 func EncCommandAsString(s string, vname string) string {
 	switch s {
-	case "uint", "uint8", "uint16", "uint31", "uint64":
+	case "uint", "uint8", "uint16", "uint32", "uint64":
 		return "f.ee.encodeUint(uint64(" + vname + "))"
-	case "int", "int8", "int16", "int31", "int64":
+	case "int", "int8", "int16", "int32", "int64":
 		return "f.ee.encodeInt(int64(" + vname + "))"
 	case "string":
 		return "f.ee.encodeString(c_UTF8, " + vname + ")"
@@ -318,12 +318,21 @@ func main() {
 		"int64",
 		"bool",
 	}
-	mapvaltypes := map[string]bool{
-		"string":      true,
-		"interface{}": true,
-		"int":         true,
-		"int64":       true,
-		"uint64":      true,
+	// keep as slice, so it is in specific iteration order.
+	// Initial order was uint64, string, interface{}, int, int64
+	mapvaltypes := []string{
+		"interface{}",
+		"string",
+		"uint",
+		"uint32",
+		"uint64",
+		"int",
+		"int32",
+		"int64",
+	}
+	mapvaltypes2 := make(map[string]bool)
+	for _, s := range mapvaltypes {
+		mapvaltypes2[s] = true
 	}
 	var gt genTmpl
 	// For each slice or map type, there must be a (symetrical) Encode and Decode fast-path function
@@ -331,10 +340,10 @@ func main() {
 		if s != "uint8" { // do not generate fast path for slice of bytes. Treat specially already.
 			gt.Values = append(gt.Values, genInfo{true, "", s})
 		}
-		if !mapvaltypes[s] {
+		if !mapvaltypes2[s] {
 			gt.Values = append(gt.Values, genInfo{false, s, s})
 		}
-		for ms, _ := range mapvaltypes {
+		for _, ms := range mapvaltypes {
 			gt.Values = append(gt.Values, genInfo{false, s, ms})
 		}
 	}

Some files were not shown because too many files changed in this diff