diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-26 15:48:54 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-26 15:48:54 +0000 |
commit | 664733f1a3cfedbb4cde3815b61d9b87dcc42387 (patch) | |
tree | 050c5d6ecabcdbb14c27d8023669f35c0409fbc3 | |
parent | 0d42ddff7037c138d1df602158f80f9af914e927 (diff) | |
download | busybox-w32-664733f1a3cfedbb4cde3815b61d9b87dcc42387.tar.gz busybox-w32-664733f1a3cfedbb4cde3815b61d9b87dcc42387.tar.bz2 busybox-w32-664733f1a3cfedbb4cde3815b61d9b87dcc42387.zip |
sort: two small optimizations
-rw-r--r-- | coreutils/sort.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c index 5f91bcb44..c23bf9c60 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -70,8 +70,7 @@ static char *get_key(char *str, struct sort_key *key, int flags) | |||
70 | for (i = 1; i < key->range[2*j] + j; i++) { | 70 | for (i = 1; i < key->range[2*j] + j; i++) { |
71 | /* Skip leading blanks or first separator */ | 71 | /* Skip leading blanks or first separator */ |
72 | if (str[end]) { | 72 | if (str[end]) { |
73 | if (!key_separator && isspace(str[end])) | 73 | if (!key_separator) |
74 | /* TODO: remove "&& isspace(str[end])" */ | ||
75 | while (isspace(str[end])) end++; | 74 | while (isspace(str[end])) end++; |
76 | } | 75 | } |
77 | /* Skip body of key */ | 76 | /* Skip body of key */ |
@@ -158,7 +157,7 @@ static int compare_keys(const void *xarg, const void *yarg) | |||
158 | struct sort_key *key; | 157 | struct sort_key *key; |
159 | 158 | ||
160 | for (key = key_list; !retval && key; key = key->next_key) { | 159 | for (key = key_list; !retval && key; key = key->next_key) { |
161 | flags = (key->flags) ? key->flags : global_flags; | 160 | flags = key->flags ? key->flags : global_flags; |
162 | /* Chop out and modify key chunks, handling -dfib */ | 161 | /* Chop out and modify key chunks, handling -dfib */ |
163 | x = get_key(*(char **)xarg, key, flags); | 162 | x = get_key(*(char **)xarg, key, flags); |
164 | y = get_key(*(char **)yarg, key, flags); | 163 | y = get_key(*(char **)yarg, key, flags); |
@@ -181,7 +180,8 @@ static int compare_keys(const void *xarg, const void *yarg) | |||
181 | #if ENABLE_FEATURE_SORT_BIG | 180 | #if ENABLE_FEATURE_SORT_BIG |
182 | case FLAG_g: { | 181 | case FLAG_g: { |
183 | char *xx, *yy; | 182 | char *xx, *yy; |
184 | double dx = strtod(x, &xx), dy = strtod(y, &yy); | 183 | double dx = strtod(x, &xx); |
184 | double dy = strtod(y, &yy); | ||
185 | /* not numbers < NaN < -infinity < numbers < +infinity) */ | 185 | /* not numbers < NaN < -infinity < numbers < +infinity) */ |
186 | if (x == xx) | 186 | if (x == xx) |
187 | retval = (y == yy ? 0 : -1); | 187 | retval = (y == yy ? 0 : -1); |
@@ -217,26 +217,27 @@ static int compare_keys(const void *xarg, const void *yarg) | |||
217 | else if (!yy) | 217 | else if (!yy) |
218 | retval = 1; | 218 | retval = 1; |
219 | else | 219 | else |
220 | retval = (dx==thyme.tm_mon) ? 0 : dx-thyme.tm_mon; | 220 | retval = (dx == thyme.tm_mon) ? 0 : dx - thyme.tm_mon; |
221 | break; | 221 | break; |
222 | } | 222 | } |
223 | /* Full floating point version of -n */ | 223 | /* Full floating point version of -n */ |
224 | case FLAG_n: { | 224 | case FLAG_n: { |
225 | double dx = atof(x), dy =atof(y); | 225 | double dx = atof(x); |
226 | double dy = atof(y); | ||
226 | retval = (dx > dy) ? 1 : ((dx < dy) ? -1 : 0); | 227 | retval = (dx > dy) ? 1 : ((dx < dy) ? -1 : 0); |
227 | break; | 228 | break; |
228 | } | 229 | } |
229 | } | 230 | } /* switch */ |
230 | /* Free key copies. */ | 231 | /* Free key copies. */ |
231 | if (x != *(char **)xarg) free(x); | 232 | if (x != *(char **)xarg) free(x); |
232 | if (y != *(char **)yarg) free(y); | 233 | if (y != *(char **)yarg) free(y); |
233 | if (retval) break; | 234 | /* if (retval) break; - done by for() anyway */ |
234 | #else | 235 | #else |
235 | /* Integer version of -n for tiny systems */ | 236 | /* Integer version of -n for tiny systems */ |
236 | case FLAG_n: | 237 | case FLAG_n: |
237 | retval = atoi(x) - atoi(y); | 238 | retval = atoi(x) - atoi(y); |
238 | break; | 239 | break; |
239 | } | 240 | } /* switch */ |
240 | #endif | 241 | #endif |
241 | } | 242 | } |
242 | /* Perform fallback sort if necessary */ | 243 | /* Perform fallback sort if necessary */ |