[rygel/wip/ruih] wip: Rework StringBuilder use
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/wip/ruih] wip: Rework StringBuilder use
- Date: Sun, 19 Oct 2014 14:11:29 +0000 (UTC)
commit b82360cce47dde77db5e30fc9519ffb5d76420a4
Author: Jens Georg <mail jensge org>
Date: Sun Oct 19 16:09:51 2014 +0200
wip: Rework StringBuilder use
Signed-off-by: Jens Georg <mail jensge org>
src/librygel-ruih/rygel-ruih-icon-elem.vala | 14 +++++---------
src/librygel-ruih/rygel-ruih-protocol-elem.vala | 9 +++++----
src/librygel-ruih/rygel-ruih-ui-elem.vala | 13 +++++++------
src/librygel-ruih/rygel-ruih-ui-listing.vala | 6 ++----
4 files changed, 19 insertions(+), 23 deletions(-)
---
diff --git a/src/librygel-ruih/rygel-ruih-icon-elem.vala b/src/librygel-ruih/rygel-ruih-icon-elem.vala
index 2aa2f23..a98a21f 100644
--- a/src/librygel-ruih/rygel-ruih-icon-elem.vala
+++ b/src/librygel-ruih/rygel-ruih-icon-elem.vala
@@ -80,7 +80,8 @@ protected class IconElem : UIListing {
return true;
}
- public override string to_ui_listing (ArrayList<FilterEntry> filters) {
+ public override void to_ui_listing (ArrayList<FilterEntry> filters,
+ StringBuilder sb) {
var elements = new HashMap<string, string> ();
if ((this.mime_type != null) &&
@@ -106,14 +107,9 @@ protected class IconElem : UIListing {
}
if (elements.size > 0) {
- var sb = new StringBuilder ();
- sb.append ("<" + ICON + ">\n");
- sb.append (this.to_xml (elements));
- sb.append ("</" + ICON + ">\n");
-
- return sb.str;
+ sb.append_c ('<').append (ICON).append (">\n");
+ this.to_xml (elements, sb);
+ sb.append ("</").append (ICON).append (">\n");
}
-
- return "";
}
}
diff --git a/src/librygel-ruih/rygel-ruih-protocol-elem.vala b/src/librygel-ruih/rygel-ruih-protocol-elem.vala
index c10dd34..b68e9d7 100644
--- a/src/librygel-ruih/rygel-ruih-protocol-elem.vala
+++ b/src/librygel-ruih/rygel-ruih-protocol-elem.vala
@@ -121,8 +121,9 @@ protected class ProtocolElem : UIListing {
var sb = new StringBuilder ();
if (matches) {
- sb.append ("<" + PROTOCOL + " " +
- SHORT_NAME + "=\"" + this.short_name + "\">\n");
+ sb.append_c ('<').append (PROTOCOL).append_c (' ')
+ .append (SHORT_NAME).append ("=\"")
+ .append (this.short_name).append ("\">\n");
if (this.uris.size > 0) {
foreach (var uri in this.uris)
@@ -132,8 +133,8 @@ protected class ProtocolElem : UIListing {
.append ("</").append (URI).append (">\n");
}
}
- sb.append (this.to_xml (elements));
- sb.append ("</" + PROTOCOL + ">\n");
+ this.to_xml (elements, sb);
+ sb.append ("</").append (PROTOCOL).append (">\n");
}
return sb.str;
diff --git a/src/librygel-ruih/rygel-ruih-ui-elem.vala b/src/librygel-ruih/rygel-ruih-ui-elem.vala
index 9d576ba..581d2ba 100644
--- a/src/librygel-ruih/rygel-ruih-ui-elem.vala
+++ b/src/librygel-ruih/rygel-ruih-ui-elem.vala
@@ -130,20 +130,21 @@ protected class UIElem : UIListing
match = true;
}
- var sb = new StringBuilder ("<" + UI + ">\n");
- sb.append (this.to_xml (elements));
+ var sb = new StringBuilder ("<")
+ sb.append (UI).append (">\n");
+ this.to_xml (elements, sb);
var icon_sb = new StringBuilder ();
foreach (var icon in this.icons) {
- icon_sb.append (icon.to_ui_listing (filters));
+ icon.to_ui_listing (filters, icon_sb);
}
// Only display list if there is something to display
if (icon_sb.str.length > 0) {
match = true;
- sb.append ("<" + ICONLIST + ">\n");
+ sb.append ("<").append (ICONLIST).append (">\n");
sb.append (icon_sb.str);
- sb.append ("</" + ICONLIST + ">\n");
+ sb.append ("</").append (ICONLIST).append (">\n");
}
var protocol_sb = new StringBuilder ();
@@ -158,7 +159,7 @@ protected class UIElem : UIListing
}
}
- sb.append ("</" + UI + ">\n");
+ sb.append ("</").append (UI).append (">\n");
if (match) {
return sb.str;
} else {
diff --git a/src/librygel-ruih/rygel-ruih-ui-listing.vala b/src/librygel-ruih/rygel-ruih-ui-listing.vala
index 86bb45c..e7e96a6 100644
--- a/src/librygel-ruih/rygel-ruih-ui-listing.vala
+++ b/src/librygel-ruih/rygel-ruih-ui-listing.vala
@@ -47,13 +47,11 @@ public abstract class UIListing
ArrayList<FilterEntry> filters);
public abstract string to_ui_listing (ArrayList<FilterEntry> filters);
- public string to_xml (Gee.HashMap<string, string> hash_map) {
- var sb = new StringBuilder ();
+ public void to_xml (Gee.HashMap<string, string> hash_map,
+ StringBuilder sb) {
foreach (var e in hash_map.entries) {
sb.append_printf ("<%s>%s</%s>\n", e.key, e.value, e.key);
}
-
- return sb.str;
}
// Convenience method to avoid a lot of inline loops
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]