banshee r5176 - in trunk/banshee: . src/Core/Banshee.Core/Banshee.Base
- From: blorentz svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r5176 - in trunk/banshee: . src/Core/Banshee.Core/Banshee.Base
- Date: Tue, 31 Mar 2009 16:46:46 +0000 (UTC)
Author: blorentz
Date: Tue Mar 31 16:46:46 2009
New Revision: 5176
URL: http://svn.gnome.org/viewvc/banshee?rev=5176&view=rev
Log:
2009-03-31 Bertrand Lorentz <bertrand lorentz gmail com>
* src/Core/Banshee.Core/Banshee.Base/Localization.cs: Reduce startup
time by compiling and caching XPath expressions (BGO #577100).
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Localization.cs
Modified: trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Localization.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Localization.cs (original)
+++ trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Localization.cs Tue Mar 31 16:46:46 2009
@@ -28,6 +28,7 @@
using System;
using System.Xml;
+using System.Xml.XPath;
using System.Collections.Generic;
using System.Runtime.InteropServices;
@@ -38,6 +39,7 @@
private static string [] default_languages = { "C" };
private static string [] instance_languages = null;
private static string [] instance_xml_languages = null;
+ private static XPathExpression [] instance_xpath_expressions = null;
public static string [] Languages {
get {
@@ -79,17 +81,35 @@
return instance_xml_languages;
}
}
+
+ public static XPathExpression [] XPathExpressions {
+ get {
+ if(instance_xpath_expressions != null) {
+ return instance_xpath_expressions;
+ }
+
+ List<XPathExpression> xpath_exps = new List<XPathExpression>();
+ foreach(string xml_lang in XmlLanguages) {
+ xpath_exps.Add(XPathExpression.Compile(String.Format("self::node()[lang('{0}')]", xml_lang)));
+ }
+
+ instance_xpath_expressions = xpath_exps.ToArray();
+
+ return instance_xpath_expressions;
+ }
+ }
public static XmlNode SelectSingleNode(XmlNode parent, string query)
{
XmlNodeList list = parent.SelectNodes(query);
XmlNode result = null;
- foreach(string language in XmlLanguages) {
+ foreach(XPathExpression xpath_exp in XPathExpressions) {
foreach(XmlNode child in list) {
- XmlNode lang_child = child.SelectSingleNode(String.Format("self::node()[lang('{0}')]", language));
- if(lang_child != null) {
- result = lang_child;
+ XPathNavigator nav = child.CreateNavigator();
+ XPathNavigator lang_child = nav.SelectSingleNode(xpath_exp);
+ if(lang_child != null && lang_child is IHasXmlNode) {
+ result = ((IHasXmlNode)lang_child).GetNode();
break;
}
}
@@ -107,11 +127,12 @@
XmlNodeList list = parent.SelectNodes(query);
List<XmlNode> result = new List<XmlNode>();
- foreach(string language in XmlLanguages) {
+ foreach(XPathExpression xpath_exp in XPathExpressions) {
foreach(XmlNode child in list) {
- XmlNode lang_child = child.SelectSingleNode(String.Format("self::node()[lang('{0}')]", language));
- if(lang_child != null) {
- result.Add(lang_child);
+ XPathNavigator nav = child.CreateNavigator();
+ XPathNavigator lang_child = nav.SelectSingleNode(xpath_exp);
+ if(lang_child != null && lang_child is IHasXmlNode) {
+ result.Add(((IHasXmlNode)lang_child).GetNode());
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]