public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
From: agk@sourceware.org
To: lvm-devel@redhat.com, lvm2-cvs@sourceware.org
Subject: LVM2 ./WHATS_NEW lib/misc/lvm-string.c
Date: Tue, 28 Sep 2010 01:29:00 -0000	[thread overview]
Message-ID: <20100928012908.16589.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk@sourceware.org	2010-09-28 01:29:07

Modified files:
	.              : WHATS_NEW 
	lib/misc       : lvm-string.c 

Log message:
	Speed up unquoting of quoted double quotes and backslashes.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1737&r2=1.1738
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.c.diff?cvsroot=lvm2&r1=1.22&r2=1.23

--- LVM2/WHATS_NEW	2010/09/27 19:09:34	1.1737
+++ LVM2/WHATS_NEW	2010/09/28 01:29:06	1.1738
@@ -1,5 +1,6 @@
 Version 2.02.75 - 
 =====================================
+  Speed up unquoting of quoted double quotes and backslashes.
   Speed up CRC32 calculations by using a larger lookup table.
 
 Version 2.02.74 - 24th September 2010
--- LVM2/lib/misc/lvm-string.c	2010/09/23 12:02:34	1.22
+++ LVM2/lib/misc/lvm-string.c	2010/09/28 01:29:07	1.23
@@ -108,33 +108,64 @@
 	}
 }
 
+static void _unquote_one_character(char *src, const char orig_char,
+				   const char quote_char)
+{
+	char *out;
+	char s, n;
+
+	/* Optimise for the common case where no changes are needed. */
+	while ((s = *src++)) {
+		if (s == quote_char &&
+		    ((n = *src) == orig_char || n == quote_char)) {
+			out = src++;
+			*(out - 1) = n;
+
+			while ((s = *src++)) {
+				if (s == quote_char &&
+				    ((n = *src) == orig_char || n == quote_char)) {
+					s = n;
+					src++;
+				}
+				*out = s;
+				out++;
+			}
+
+			*out = '\0';
+			return;
+		}
+	}
+}
+
 /*
  * Unquote each character given in orig_char array and unquote quote_char
- * as well. The array ends up with '\0' character. Also save the first
- * occurence of each character from orig_char that was found unquoted in
- * arr_substr_first_unquoted array. This way we can process several
- * characters in one go.
+ * as well. Also save the first occurrence of each character from orig_char
+ * that was found unquoted in arr_substr_first_unquoted array. This way we can
+ * process several characters in one go.
  */
-static void _unquote_characters(char *src, const int orig_chars[],
-				const int quote_char,
+static void _unquote_characters(char *src, const char *orig_chars,
+				const int num_orig_chars, 
+				const char quote_char,
 				char *arr_substr_first_unquoted[])
 {
 	char *out = src;
-	int c;
-	int i;
+	char c, s, n;
+	unsigned i;
 
-	while (*src) {
-		for (i = 0; (c = orig_chars[i]); i++) {
-			if (*src == quote_char &&
-			    (*(src + 1) == c || *(src + 1) == quote_char)) {
+	while ((s = *src++)) {
+		for (i = 0; i < num_orig_chars; i++) {
+			c = orig_chars[i];
+			if (s == quote_char &&
+			    ((n = *src) == c || n == quote_char)) {
+				s = n;
 				src++;
 				break;
 			}
-			else if (arr_substr_first_unquoted && (*src == c) &&
-				 !arr_substr_first_unquoted[i])
+			if (arr_substr_first_unquoted && (s == c) &&
+			    !arr_substr_first_unquoted[i])
 				arr_substr_first_unquoted[i] = out;
-		}
-		*out++ = *src++;
+		};
+		*out++ = s;
 	}
 
 	*out = '\0';
@@ -229,9 +260,7 @@
  */
 void unescape_double_quotes(char *src)
 {
-	const int orig_chars[] = {'\"', '\0'};
-
-	_unquote_characters(src, orig_chars, '\\', NULL);
+	_unquote_one_character(src, '\"', '\\');
 }
 
 /*
@@ -244,10 +273,10 @@
 				  char **substr_first_unquoted_colon,
 				  char **substr_first_unquoted_at_sign)
 {
-	const int orig_chars[] = {':', '@', '\0'};
+	const char *orig_chars = ":@";
 	char *arr_substr_first_unquoted[] = {NULL, NULL, NULL};
 
-	_unquote_characters(src, orig_chars, '\\', arr_substr_first_unquoted);
+	_unquote_characters(src, orig_chars, 2, '\\', arr_substr_first_unquoted);
 
 	if (substr_first_unquoted_colon)
 		*substr_first_unquoted_colon = arr_substr_first_unquoted[0];


             reply	other threads:[~2010-09-28  1:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-28  1:29 agk [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-03-13 23:18 zkabelac
2011-03-13 22:57 zkabelac
2010-09-20 14:25 prajnoha
2004-10-11 15:59 agk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100928012908.16589.qmail@sourceware.org \
    --to=agk@sourceware.org \
    --cc=lvm-devel@redhat.com \
    --cc=lvm2-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).