[librsvg: 3/8] xml: use last_child() to check for Chars
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/8] xml: use last_child() to check for Chars
- Date: Sat, 11 May 2019 00:00:02 +0000 (UTC)
commit ea27d83c1cd8b087a240d68de439e3737ecd74d3
Author: Paolo Borelli <pborelli gnome org>
Date: Fri May 10 12:19:43 2019 +0200
xml: use last_child() to check for Chars
We have access to the last child directy, so we can simplify
the code.
rsvg_internals/src/node.rs | 14 --------------
rsvg_internals/src/xml.rs | 9 +++++++--
2 files changed, 7 insertions(+), 16 deletions(-)
---
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index 546ac656..deccaa0d 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -567,20 +567,6 @@ impl Node {
let mut specified_values = self.borrow().specified_values.borrow_mut();
specified_values.overflow = SpecifiedValue::Specified(Overflow::Hidden);
}
-
- // find the last Chars node so that we can coalesce
- // the text and avoid screwing up the Pango layouts
- pub fn find_last_chars_child(&self) -> Option<Rc<Node>> {
- for child in self.children().rev() {
- match child.get_type() {
- NodeType::Chars => return Some(child),
-
- _ => return None,
- }
- }
-
- None
- }
}
pub fn node_new(
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index e86b9fb7..927745e1 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -19,7 +19,7 @@ use crate::property_bag::PropertyBag;
use crate::style::NodeStyle;
use crate::svg::Svg;
use crate::text::NodeChars;
-use crate::xml2_load::{Xml2Parser, ParseFromStreamError};
+use crate::xml2_load::{ParseFromStreamError, Xml2Parser};
#[derive(Clone)]
enum Context {
@@ -286,7 +286,12 @@ impl XmlState {
let node = self.current_node.as_ref().unwrap();
if text.len() != 0 {
- let chars_node = if let Some(child) = node.find_last_chars_child() {
+ // When the last child is a Chars node we can coalesce
+ // the text and avoid screwing up the Pango layouts
+ let chars_node = if let Some(child) = node
+ .last_child()
+ .filter(|c| c.get_type() == NodeType::Chars)
+ {
child
} else {
let child = node_new(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]