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

A faster function to replace node by path #92

Open
idleGG opened this issue Mar 7, 2025 · 1 comment
Open

A faster function to replace node by path #92

idleGG opened this issue Mar 7, 2025 · 1 comment

Comments

@idleGG
Copy link
Contributor

idleGG commented Mar 7, 2025

Describe the solution you'd like

Add a new function to replace node field based on the old one, and use only one search by path.

The function may be like:

// File: `thrift/generic/node.go`
func (self *Node) ReplaceByPath(f func(Node) Node, path ...Path) (exist bool, err error) {
	if len(path) == 0 {
		*self = f(*self)
		return true, nil
	}
	if err := self.Check(); err != nil {
		return false, err
	}
	// search source node by path
	var v = self.GetByPath(path...)
	if v.IsError() {
		return false, v
	} else {
		exist = true
	}
	sub := f(v)
	if sub.IsError() {
		return true, sub
	}
	err = self.replace(v, sub)
	return
}
@AsterDY
Copy link
Collaborator

AsterDY commented Mar 7, 2025

welcome PR

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

No branches or pull requests

2 participants