Skip to content

Commit

Permalink
Remove old-style Walk functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zolstein authored Nov 28, 2024
1 parent 04e92f3 commit aad0112
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 40 deletions.
4 changes: 2 additions & 2 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func BenchmarkSimpleJsonSerialize(b *testing.B) {
if i > 0 {
bb.WriteRune(',')
}
err := s.Walk(ctx, i)
err := s.Elem(i).Walk(ctx)
if err != nil {
return err
}
Expand All @@ -150,7 +150,7 @@ func BenchmarkSimpleJsonSerialize(b *testing.B) {
bb.WriteString(fields[i].Name)
bb.WriteRune('"')
bb.WriteRune(':')
err := s.Walk(ctx, i)
err := s.Field(i).Walk(ctx)
if err != nil {
return err
}
Expand Down
28 changes: 0 additions & 28 deletions walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,6 @@ func (s Struct[Ctx]) Field(idx int) StructField[Ctx] {
}
}

// Walk walks a registered field of the struct value.
// idx must be in the range [0..NumFields())
func (s Struct[Ctx]) Walk(ctx Ctx, idx int) error {
return s.Field(idx).Walk(ctx)
}

func (s Struct[Ctx]) Interface() any {
return g_reflect.NewAt(s.meta.typ, s.arg.p).Elem().Interface()
}
Expand Down Expand Up @@ -264,12 +258,6 @@ func (a Array[Ctx]) Elem(idx int) ArrayElem[Ctx] {
}
}

// Walk walks an element of the array value.
// idx must be in the range [0..Len())
func (a Array[Ctx]) Walk(ctx Ctx, idx int) error {
return a.Elem(idx).Walk(ctx)
}

func (a Array[Ctx]) Interface() any {
return g_reflect.NewAt(a.meta.typ, a.arg.p).Elem().Interface()
}
Expand Down Expand Up @@ -335,12 +323,6 @@ func (s Slice[Ctx]) Elem(idx int) SliceElem[Ctx] {
}
}

// Walk walks an element of the slice value.
// idx must be in the range [0..Len())
func (s Slice[Ctx]) Walk(ctx Ctx, idx int) error {
return s.Elem(idx).Walk(ctx)
}

func (a Slice[Ctx]) Interface() any {
return g_reflect.NewAt(a.meta.typ, a.arg.p).Elem().Interface()
}
Expand Down Expand Up @@ -482,16 +464,6 @@ func (m MapEntry[Ctx]) Value() MapValue[Ctx] {
}
}

// WalkKey walks the key associated with this MapEntry.
func (m MapEntry[Ctx]) WalkKey(ctx Ctx) error {
return m.Key().Walk(ctx)
}

// WalkValue walks the value associated with this MapEntry.
func (m MapEntry[Ctx]) WalkValue(ctx Ctx) error {
return m.Value().Walk(ctx)
}

// MapKey represents a key in the map.
type MapKey[Ctx any] struct {
meta *mapMetadata[Ctx]
Expand Down
20 changes: 10 additions & 10 deletions walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func TestRegisterCompileArrayFn(t *testing.T) {
if i > 0 {
ctx.WriteRune(',')
}
err := aw.Walk(ctx, i)
err := aw.Elem(i).Walk(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestRegisterCompileSliceFn(t *testing.T) {
if i > 0 {
ctx.WriteRune(',')
}
err := sw.Walk(ctx, i)
err := sw.Elem(i).Walk(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -490,12 +490,12 @@ func TestRegisterCompileMapFn(t *testing.T) {
ctx.WriteRune(',')
}
e := iter.Entry()
err := e.WalkKey(ctx)
err := e.Key().Walk(ctx)
if err != nil {
return err
}
ctx.WriteRune(':')
err = e.WalkValue(ctx)
err = e.Value().Walk(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -817,7 +817,7 @@ func settableSliceHelper(t *testing.T) {
register.RegisterCompileSliceFn(func(typ reflect.Type) tw.WalkSliceFn[struct{}] {
return func(ctx struct{}, s tw.Slice[struct{}]) error {
for i := 0; i < s.Len(); i++ {
err := s.Walk(ctx, i)
err := s.Elem(i).Walk(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -869,7 +869,7 @@ func settableArrayHelper(t *testing.T) {
register.RegisterCompileArrayFn(func(typ reflect.Type) tw.WalkArrayFn[struct{}] {
return func(ctx struct{}, a tw.Array[struct{}]) error {
for i := 0; i < a.Len(); i++ {
err := a.Walk(ctx, i)
err := a.Elem(i).Walk(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -925,7 +925,7 @@ func settableStructHelper(t *testing.T) {
}
return func(ctx struct{}, s tw.Struct[struct{}]) error {
for i := 0; i < s.NumFields(); i++ {
err := s.Walk(ctx, i)
err := s.Field(i).Walk(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -1034,11 +1034,11 @@ func settableMapHelper(t *testing.T) {
iter := m.Iter()
for iter.Next() {
entry := iter.Entry()
err := entry.WalkKey(ctx)
err := entry.Key().Walk(ctx)
if err != nil {
return err
}
err = entry.WalkValue(ctx)
err = entry.Value().Walk(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -1448,7 +1448,7 @@ func printStruct(fields []reflect.StructField) tw.WalkStructFn[*strings.Builder]
ctx.WriteString(field.Name)
ctx.WriteRune(':')

err := sw.Walk(ctx, i)
err := sw.Field(i).Walk(ctx)
if err != nil {
return err
}
Expand Down

0 comments on commit aad0112

Please sign in to comment.