summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-08-14 22:08:16 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2011-08-14 22:09:22 -0700
commit8739d45f721feb3d05d75f5ca0afda4bacea635b (patch)
tree73ac5fe7c197da90cfdb28083f2e5093d2c94d31
parent86a40dd6acc84e5633d2fc6b45f9193fe01b23f8 (diff)
downloaddiffutils-8739d45f721feb3d05d75f5ca0afda4bacea635b.tar.gz
* src/io.c (find_and_hash_each_line): Refactor for brevity.
-rw-r--r--src/io.c235
1 files changed, 77 insertions, 158 deletions
diff --git a/src/io.c b/src/io.c
index fdb4654..0a75ab5 100644
--- a/src/io.c
+++ b/src/io.c
@@ -198,9 +198,7 @@ slurp (struct file_data *current)
static void
find_and_hash_each_line (struct file_data *current)
{
- hash_value h;
char const *p = current->prefix_end;
- unsigned char c;
lin i, *bucket;
size_t length;
@@ -215,191 +213,112 @@ find_and_hash_each_line (struct file_data *current)
lin eqs_alloc = equivs_alloc;
char const *suffix_begin = current->suffix_begin;
char const *bufend = FILE_BUFFER (current) + current->buffered;
+ bool ig_case = ignore_case;
+ enum DIFF_white_space ig_white_space = ignore_white_space;
bool diff_length_compare_anyway =
- ignore_white_space != IGNORE_NO_WHITE_SPACE;
+ ig_white_space != IGNORE_NO_WHITE_SPACE;
bool same_length_diff_contents_compare_anyway =
- diff_length_compare_anyway | ignore_case;
+ diff_length_compare_anyway | ig_case;
while (p < suffix_begin)
{
char const *ip = p;
-
- h = 0;
+ hash_value h = 0;
+ unsigned char c;
/* Hash this line until we find a newline. */
- if (ignore_case)
- switch (ignore_white_space)
- {
- case IGNORE_ALL_SPACE:
- while ((c = *p++) != '\n')
- if (! isspace (c))
- h = HASH (h, tolower (c));
- break;
-
- case IGNORE_SPACE_CHANGE:
- while ((c = *p++) != '\n')
- {
- if (isspace (c))
- {
- do
- if ((c = *p++) == '\n')
- goto hashing_done;
- while (isspace (c));
-
- h = HASH (h, ' ');
- }
-
- /* C is now the first non-space. */
- h = HASH (h, tolower (c));
- }
- break;
+ switch (ig_white_space)
+ {
+ case IGNORE_ALL_SPACE:
+ while ((c = *p++) != '\n')
+ if (! isspace (c))
+ h = HASH (h, ig_case ? tolower (c) : c);
+ break;
- case IGNORE_TAB_EXPANSION:
- case IGNORE_TAB_EXPANSION_AND_TRAILING_SPACE:
- case IGNORE_TRAILING_SPACE:
+ case IGNORE_SPACE_CHANGE:
+ while ((c = *p++) != '\n')
{
- size_t column = 0;
- while ((c = *p++) != '\n')
+ if (isspace (c))
{
- if (ignore_white_space & IGNORE_TRAILING_SPACE
- && isspace (c))
- {
- char const *p1 = p;
- unsigned char c1;
- do
- if ((c1 = *p1++) == '\n')
- {
- p = p1;
- goto hashing_done;
- }
- while (isspace (c1));
- }
-
- size_t repetitions = 1;
-
- if (ignore_white_space & IGNORE_TAB_EXPANSION)
- switch (c)
- {
- case '\b':
- column -= 0 < column;
- break;
-
- case '\t':
- c = ' ';
- repetitions = tabsize - column % tabsize;
- column = (column + repetitions < column
- ? 0
- : column + repetitions);
- break;
-
- case '\r':
- column = 0;
- break;
-
- default:
- column++;
- break;
- }
-
- c = tolower (c);
do
- h = HASH (h, c);
- while (--repetitions != 0);
+ if ((c = *p++) == '\n')
+ goto hashing_done;
+ while (isspace (c));
+
+ h = HASH (h, ' ');
}
+
+ /* C is now the first non-space. */
+ h = HASH (h, ig_case ? tolower (c) : c);
}
- break;
+ break;
- default:
- while ((c = *p++) != '\n')
- h = HASH (h, tolower (c));
- break;
- }
- else
- switch (ignore_white_space)
+ case IGNORE_TAB_EXPANSION:
+ case IGNORE_TAB_EXPANSION_AND_TRAILING_SPACE:
+ case IGNORE_TRAILING_SPACE:
{
- case IGNORE_ALL_SPACE:
- while ((c = *p++) != '\n')
- if (! isspace (c))
- h = HASH (h, c);
- break;
-
- case IGNORE_SPACE_CHANGE:
+ size_t column = 0;
while ((c = *p++) != '\n')
{
- if (isspace (c))
+ if (ig_white_space & IGNORE_TRAILING_SPACE
+ && isspace (c))
{
+ char const *p1 = p;
+ unsigned char c1;
do
- if ((c = *p++) == '\n')
- goto hashing_done;
- while (isspace (c));
-
- h = HASH (h, ' ');
+ if ((c1 = *p1++) == '\n')
+ {
+ p = p1;
+ goto hashing_done;
+ }
+ while (isspace (c1));
}
- /* C is now the first non-space. */
- h = HASH (h, c);
- }
- break;
-
- case IGNORE_TAB_EXPANSION:
- case IGNORE_TAB_EXPANSION_AND_TRAILING_SPACE:
- case IGNORE_TRAILING_SPACE:
- {
- size_t column = 0;
- while ((c = *p++) != '\n')
- {
- size_t repetitions = 1;
+ size_t repetitions = 1;
- if (ignore_white_space & IGNORE_TRAILING_SPACE
- && isspace (c))
+ if (ig_white_space & IGNORE_TAB_EXPANSION)
+ switch (c)
{
- char const *p1 = p;
- unsigned char c1;
- do
- if ((c1 = *p1++) == '\n')
- {
- p = p1;
- goto hashing_done;
- }
- while (isspace (c1));
+ case '\b':
+ column -= 0 < column;
+ break;
+
+ case '\t':
+ c = ' ';
+ repetitions = tabsize - column % tabsize;
+ column = (column + repetitions < column
+ ? 0
+ : column + repetitions);
+ break;
+
+ case '\r':
+ column = 0;
+ break;
+
+ default:
+ column++;
+ break;
}
- if (ignore_white_space & IGNORE_TAB_EXPANSION)
- switch (c)
- {
- case '\b':
- column -= 0 < column;
- break;
-
- case '\t':
- c = ' ';
- repetitions = tabsize - column % tabsize;
- column = (column + repetitions < column
- ? 0
- : column + repetitions);
- break;
-
- case '\r':
- column = 0;
- break;
-
- default:
- column++;
- break;
- }
+ if (ig_case)
+ c = tolower (c);
- do
- h = HASH (h, c);
- while (--repetitions != 0);
- }
- }
- break;
+ do
+ h = HASH (h, c);
+ while (--repetitions != 0);
+ }
+ }
+ break;
- default:
+ default:
+ if (ig_case)
+ while ((c = *p++) != '\n')
+ h = HASH (h, tolower (c));
+ else
while ((c = *p++) != '\n')
h = HASH (h, c);
- break;
- }
+ break;
+ }
hashing_done:;
@@ -415,7 +334,7 @@ find_and_hash_each_line (struct file_data *current)
complete line, put it into buckets[-1] so that it can
compare equal only to the other file's incomplete line
(if one exists). */
- if (ignore_white_space < IGNORE_TRAILING_SPACE)
+ if (ig_white_space < IGNORE_TRAILING_SPACE)
bucket = &buckets[-1];
}