integrate request builder into HTTP client for googleapis support (#157)
Some checks failed
coverage / build (push) Successful in 2m19s
test / test (push) Failing after 17m15s

This commit is contained in:
2025-09-23 15:30:15 +05:00
committed by GitHub
parent b37fca95cf
commit 24801750a7
32 changed files with 9491 additions and 1736 deletions

44
builder/used_fields.go Normal file
View File

@@ -0,0 +1,44 @@
package builder
import "strings"
// usedFields stores keys and their top-level parts,
// turning top-level lookups from O(N) into O(1).
type usedFields struct {
full map[string]struct{}
top map[string]struct{}
}
func newUsedFields() *usedFields {
return &usedFields{
full: make(map[string]struct{}),
top: make(map[string]struct{}),
}
}
// add inserts a new key and updates the top-level index.
func (u *usedFields) add(key string) {
u.full[key] = struct{}{}
top := key
if i := strings.IndexByte(key, '.'); i != -1 {
top = key[:i]
}
u.top[top] = struct{}{}
}
// hasTopLevelKey checks if a top-level key exists.
func (u *usedFields) hasTopLevelKey(top string) bool {
_, ok := u.top[top]
return ok
}
// hasFullKey checks if an exact key exists.
func (u *usedFields) hasFullKey(key string) bool {
_, ok := u.full[key]
return ok
}
// len returns the number of full keys stored in the set.
func (u *usedFields) len() int {
return len(u.full)
}