redefiniendo el builder

packs2
DEV 3 years ago
parent fe9690a7f3
commit 2d01ac5785

@ -154,7 +154,7 @@ func BenchmarkListJSON (b *testing.B) {
//var ma = map[string]string {"{asd1/>":"344343","{asd2/>":"4343434","{asd41/>":"frtrtrtr"} //var ma = map[string]string {"{asd1/>":"344343","{asd2/>":"4343434","{asd41/>":"frtrtrtr"}
var ma = map[string]int {"{basd1/>":344343,"{casd2/>":4343434,"{asd41/>":67,"{ba2sd1/>":344343,"{11casd2/>":4343434,"{33asd41/>":67} var mas = map[string]int {"{basd1/>":344343,"{casd2/>":4343434,"{asd41/>":67,"{ba2sd1/>":344343,"{11casd2/>":4343434,"{33asd41/>":67}
func BenchmarkMapPack (b *testing.B) { func BenchmarkMapPack (b *testing.B) {
@ -172,3 +172,108 @@ func BenchmarkMapJSON (b *testing.B) {
j.Marshal(ma) j.Marshal(ma)
} }
} }
var ma = map[string]string {
"clave0": "valor123",
"clave1": "rojo",
"clave2": "valor456",
"clave3": "azul",
"clave4": "valor789",
"clave5": "verde",
"clave6": "valor012",
"clave7": "amarillo",
"clave8": "valor345",
"clave9": "naranja",
"clave10": "valor678",
"clave11": "morado",
"clave12": "valor901",
"clave13": "grande",
"clave14": "valor234",
"clave15": "pequeño",
"clave16": "valor567",
"clave17": "rápido",
"clave18": "valor890",
"clave19": "lento",
"clave20": "valor123",
"clave21": "rojo",
"clave22": "valor456",
"clave23": "azul",
"clave24": "valor789",
"clave25": "verde",
"clave26": "valor012",
"clave27": "amarillo",
"clave28": "valor345",
"clave29": "naranja",
"clave30": "valor678",
"clave31": "morado",
"clave32": "valor901",
"clave33": "grande",
"clave34": "valor234",
"clave35": "pequeño",
"clave36": "valor567",
"clave37": "rápido",
"clave38": "valor890",
"clave39": "lento",
"clave40": "valor123",
"clave41": "rojo",
"clave42": "valor456",
"clave43": "azul",
"clave44": "valor789",
"clave45": "verde",
"clave46": "valor012",
"clave47": "amarillo",
"clave48": "valor345",
"clave49": "naranja",
"clave50": "valor678",
"clave51": "morado",
"clave52": "valor901",
"clave53": "grande",
"clave54": "valor234",
"clave55": "pequeño",
"clave56": "valor567",
"clave57": "rápido",
"clave58": "valor890",
"clave59": "lento",
"clave60": "valor123",
"clave61": "rojo",
"clave62": "valor456",
"clave63": "azul",
"clave64": "valor789",
"clave65": "verde",
"clave66": "valor012",
"clave67": "amarillo",
"clave68": "valor345",
"clave69": "naranja",
"clave70": "valor678",
"clave71": "morado",
"clave72": "valor901",
"clave73": "grande",
"clave74": "valor234",
"clave75": "pequeño",
"clave76": "valor567",
"clave77": "rápido",
"clave78": "valor890",
"clave79": "lento",
"clave80": "valor123",
"clave81": "rojo",
"clave82": "valor456",
"clave83": "azul",
"clave84": "valor789",
"clave85": "verde",
"clave86": "valor012",
"clave87": "amarillo",
"clave88": "valor345",
"clave89": "naranja",
"clave90": "valor678",
"clave91": "morado",
"clave92": "valor901",
"clave93": "grande",
"clave94": "valor234",
"clave95": "pequeño",
"clave96": "valor567",
"clave97": "rápido",
"clave98": "valor890",
"clave99": "lento",
}

@ -30,6 +30,9 @@ import (
"unicode/utf8" "unicode/utf8"
) )
const startDetectingCyclesAfter = 100
var ( var (
G = struct { G = struct {
hex string hex string

@ -26,7 +26,6 @@ package js
import ( import (
"activething.com/go/gogo/packs" "activething.com/go/gogo/packs"
"encoding" "encoding"
"fmt"
"reflect" "reflect"
"sort" "sort"
"strconv" "strconv"
@ -68,6 +67,15 @@ func (m typeMapPacker) pack (s *packs.State, v reflect.Value, _ Flags) {
mi := v.MapRange() mi := v.MapRange()
ls := make([]typeMapEntry,v.Len()) ls := make([]typeMapEntry,v.Len())
if s.Level > startDetectingCyclesAfter {
pt := v.UnsafePointer()
if _,hs := s.Checks[pt]; hs {
s.SetError(packs.G.ErrRedundantPack)
}
s.Checks[pt]=struct{}{}
defer delete(s.Checks,pt)
}
for i:=0; mi.Next(); i++ { for i:=0; mi.Next(); i++ {
ls[i] = typeMapEntry{ ls[i] = typeMapEntry{
@ -75,7 +83,6 @@ func (m typeMapPacker) pack (s *packs.State, v reflect.Value, _ Flags) {
} }
if er := m.keyStringer(&ls[i], mi.Key()); er != nil { if er := m.keyStringer(&ls[i], mi.Key()); er != nil {
fmt.Printf("Error Ke %d--%v\n",mi.Key(),mi.Key().Type())
s.SetError(er) s.SetError(er)
return return
} }
@ -153,7 +160,6 @@ func buildKeyStringer(rt reflect.Type) func(me *typeMapEntry, key reflect.Value)
return func(e *typeMapEntry, k reflect.Value) error { return func(e *typeMapEntry, k reflect.Value) error {
k = k.Elem() k = k.Elem()
fmt.Printf("Ejecutando packer general\n %v\n",k)
if k.Type().Kind() == reflect.String { if k.Type().Kind() == reflect.String {
e.key = k.String() e.key = k.String()
e.flags = FlagScapeHTML e.flags = FlagScapeHTML

Loading…
Cancel
Save

Powered by TurnKey Linux.