-
Notifications
You must be signed in to change notification settings - Fork 21
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
BaseTransformer #4528
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4528?orig=1 |
@dcsobral said: The solution suggested has a big problem (or consequence) -- non-transformed XMLs still generate new data. Or, speaking through code, val a = <a><b/></a>
val b = new RuleTransformer(new RewriteRule {})(a)
a eq b This is true presently, would be false with either of the suggested modifications. It would also break this code: if (ch eq nch) n
else Elem(n.prefix, n.label, n.attributes, n.scope, nch: _*) I think a better solution would be something like this: def transform(ns: Seq[Node]): Seq[Node] = {
val changed = ns flatMap transform
if (changed.length != ns.length || (changed, ns).zipped.exists(_ != _)) changed
else ns
} That said, I never realized that fixing the double call to |
@dcsobral said: Specifically, the solution here only preserves children of a node if none of the siblings is modified. The solution there preserves all nodes where no changes are made. |
@SethTisue said: Interested community members: if you consider this issue significant, feel free to open a new issue for it on GitHub, with links in both directions. |
=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===
Try to run code below
=== What is the expected behavior? ===
script should output
0 -> Hello Example
=== What do you see instead? ===
0 -> Hello Example
1 -> Hello Example
2 -> Hello Example
...
30 -> Hello Example
31 -> Hello Example
transform function called 32 times
=== Additional information ===
Bug in BaseTransformer, you should avoid calling transform (recursive) function 2 times
For example you can change current definition by following
def transform(ns: Seq[Node]): Seq[Node] =
if (ns.isEmpty) ns
else {
val head = ns.head
val transformed = transform(ns.head)
(if (head eq transformed) head else transformed) ++ transform(ns.tail)
}
};
or just
def transform(ns: Seq[Node]): Seq[Node] =
if (ns.isEmpty) ns else transform(ns.head) ++ transform(ns.tail)
If you need more info please let me know
=== What versions of the following are you using? ===
The text was updated successfully, but these errors were encountered: