Skip to content

why not use map/hash instead of for-loop #395

@ORESoftware

Description

@ORESoftware

there's a for loop here for every call, like so:

	in.Delim('{')
	for !in.IsDelim('}') {
		key := in.UnsafeFieldName(false)
		in.WantColon()
		if in.IsNull() {
			in.Skip()
			in.WantComma()
			continue
		}
		switch key {
		case "ErrId":
			out.ErrId = string(in.String())
		case "ErrMessage":
			out.ErrMessage = string(in.String())
		default:
			in.SkipRecursive()
		}
		in.WantComma()
	}
	in.Delim('}')

I am wondering why the code generator doesn't just generate map/hash lookup calls and avoid a for-loop altogether? Might be a good reason, not sure yet

so instead, would look like this:

	in.Delim('{')
	
	 out.ErrId = x("ErrId", string(in.String()))
	 out.ErrMessage = x("ErrMessage", in.String())
	
	in.Delim('}')

if a field had no value, then I guess zero value is ok?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions