Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upIterative serialization of nodes #16749
Conversation
highfive
commented
May 5, 2017
|
@nox review ping! |
|
This looks correct, but the commits need to be squashed together, and I would appreciate if you would write a proper explanation in the commit, specifically how |
| if stack.is_empty() { | ||
| Ok(()) | ||
| } else { | ||
| Err(io::Error::new(io::ErrorKind::Other, "Stack is not empty!!!!")) |
This comment has been minimized.
This comment has been minimized.
nox
May 12, 2017
Member
What's that for? If this isn't empty, this is a logic error and should probably panic instead.
This comment has been minimized.
This comment has been minimized.
| roots.next().unwrap(); | ||
| } | ||
| 'traversal: for root in roots { | ||
| let node = root.r(); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| } | ||
| 'traversal: for root in roots { | ||
| let node = root.r(); | ||
| match node.type_id() { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
over the tree generated by the node in preorder using a vector as a stack. When we call the serializer's method start_elem, we add a tuple with the node's name and the total number of children. We substract one from the number of children of the last element of the vector when we serialize a node or when we call the serializer's method end_elem. The purpose of this stack is to take into account which nodes need to be ended by the serializer and when they need to be ended. If the last element of the vector has no children left, it is removed from the vector and ended by the serializer using end_elem. Another way to think about this, is that the last element of the vector always contains the name of the parent of the current node during the iteration over the tree.
|
OK @nox I believe it's ready |
|
@bors-servo r+ |
|
|
Iterative serialization of nodes <!-- Please describe your changes on the following line: --> This serializes the nodes in an iterative way and now it doesn't crash when serializing a deep tree --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #16696 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16749) <!-- Reviewable:end -->
|
|
You broke serialization of templates. |
|
Ok the problem is that I didn't include this part: https://github.com/servo/servo/blob/master/components/script/dom/servoparser/html.rs#L141 The thing is, We are traversing the tree in preorder and then we don't know which nodes are the children of the current node. should I try to downcast to HTMLTemplateElement and upcast to Node every node? |
|
I would make |
|
Oh never mind, I see what the problem is. You probably want to make a new iterator, somehow. |
|
could you tell me what do you have in mind? |
|
You need a new iterator, that does exactly the same traversal as the one returned by |
ghost commentedMay 5, 2017
•
edited by ghost
This serializes the nodes in an iterative way and now it doesn't crash when serializing a deep tree
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is