Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ORESoftware opened this issue Feb 18, 2024 · 1 comment
Open

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

ORESoftware opened this issue Feb 18, 2024 · 1 comment

Comments

@ORESoftware
Copy link

ORESoftware commented Feb 18, 2024

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?

@ORESoftware
Copy link
Author

ORESoftware commented Feb 19, 2024

I think I know why, it's going character by character; so the for loop is operating on a per character basis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant