beagle r4537 - branches/beagle-lucene2_1/Util
- From: dbera svn gnome org
- To: svn-commits-list gnome org
- Subject: beagle r4537 - branches/beagle-lucene2_1/Util
- Date: Sun, 24 Feb 2008 17:21:32 +0000 (GMT)
Author: dbera
Date: Sun Feb 24 17:21:32 2008
New Revision: 4537
URL: http://svn.gnome.org/viewvc/beagle?rev=4537&view=rev
Log:
Fix a previously missed problem in SafeProcess. Some micro-optimizations in the hex escape/unescape methods in the StringFu class.
Modified:
branches/beagle-lucene2_1/Util/SafeProcess.cs
branches/beagle-lucene2_1/Util/StringFu.cs
Modified: branches/beagle-lucene2_1/Util/SafeProcess.cs
==============================================================================
--- branches/beagle-lucene2_1/Util/SafeProcess.cs (original)
+++ branches/beagle-lucene2_1/Util/SafeProcess.cs Sun Feb 24 17:21:32 2008
@@ -128,7 +128,7 @@
env = new string [env_dict.Count + 2];
int count = 0;
foreach (DictionaryEntry entry in env_dict)
- if (entry.Key != "LANG")
+ if ((string) entry.Key != "LANG")
env [count ++] = String.Concat (entry.Key, "=", entry.Value);
env [count ++] = "LANG=C";
Modified: branches/beagle-lucene2_1/Util/StringFu.cs
==============================================================================
--- branches/beagle-lucene2_1/Util/StringFu.cs (original)
+++ branches/beagle-lucene2_1/Util/StringFu.cs Sun Feb 24 17:21:32 2008
@@ -26,6 +26,7 @@
using System;
using System.Collections;
+using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
@@ -415,9 +416,14 @@
static public string HexEscape (string str)
{
- StringBuilder builder = new StringBuilder ();
+ int index = -1;
+ if ((index = str.IndexOfAny (CharsToQuote)) == -1)
+ return str;
+
+ StringBuilder builder = new StringBuilder (str, 0, index, str.Length << 1);
- foreach (char c in str) {
+ for (; index < str.Length; ++ index) {
+ char c = str [index];
if (ArrayFu.IndexOfChar (CharsToQuote, c) != -1)
builder.Append (Uri.HexEscape (c));
@@ -439,23 +445,26 @@
// Translate all %xx codes into real characters
static public string HexUnescape (string str)
{
- ArrayList bytes = new ArrayList ();
- byte[] sub_bytes;
int i, pos = 0;
+ if ((i = str.IndexOf ('%')) == -1)
+ return str;
- while ((i = str.IndexOf ('%', pos)) != -1) {
+ List<byte> bytes = new List<byte> (str.Length);
+ byte[] sub_bytes;
+
+ do {
sub_bytes = Encoding.UTF8.GetBytes (str.Substring (pos, i - pos));
bytes.AddRange (sub_bytes);
pos = i;
char unescaped = Uri.HexUnescape (str, ref pos);
- bytes.Add ((byte) unescaped);
- }
+ bytes.Add (Convert.ToByte (unescaped));
+ } while ((i = str.IndexOf ('%', pos)) != -1);
sub_bytes = Encoding.UTF8.GetBytes (str.Substring (pos, str.Length - pos));
bytes.AddRange (sub_bytes);
- return Encoding.UTF8.GetString ((byte[]) bytes.ToArray (typeof (byte)));
+ return Encoding.UTF8.GetString (bytes.ToArray ());
}
// These strings should never be exposed to the user.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]