1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Implement xdigit_to_xchar more efficiently.

This commit is contained in:
hniksic 2003-09-15 10:50:43 -07:00
parent 016867ca33
commit ea8a108b1f
4 changed files with 62 additions and 31 deletions

View File

@ -1,3 +1,15 @@
2003-09-15 Hrvoje Niksic <hniksic@xemacs.org>
* wget.h (XDIGIT_TO_XCHAR): Implement as index into a literal
string.
(XDIGIT_TO_xchar): Ditto.
2003-09-15 Hrvoje Niksic <hniksic@xemacs.org>
* utils.c: Change the type of timer-related functions from long to
double, for better precision. On machines supporting gettimeofday
the timers now work with granularity of less than one millisecond.
2003-09-15 Hrvoje Niksic <hniksic@xemacs.org> 2003-09-15 Hrvoje Niksic <hniksic@xemacs.org>
* cookies.c (parse_set_cookies): Fixed the parser to handle more * cookies.c (parse_set_cookies): Fixed the parser to handle more

View File

@ -1551,11 +1551,11 @@ struct wget_timer {
/* The most recent elapsed time, calculated by wtimer_elapsed(). /* The most recent elapsed time, calculated by wtimer_elapsed().
Measured in milliseconds. */ Measured in milliseconds. */
long elapsed_last; double elapsed_last;
/* Approximately, the time elapsed between the true start of the /* Approximately, the time elapsed between the true start of the
measurement and the time represented by START. */ measurement and the time represented by START. */
long elapsed_pre_start; double elapsed_pre_start;
}; };
/* Allocate a timer. It is not legal to do anything with a freshly /* Allocate a timer. It is not legal to do anything with a freshly
@ -1624,12 +1624,12 @@ wtimer_reset (struct wget_timer *wt)
wt->elapsed_pre_start = 0; wt->elapsed_pre_start = 0;
} }
static long static double
wtimer_sys_diff (wget_sys_time *wst1, wget_sys_time *wst2) wtimer_sys_diff (wget_sys_time *wst1, wget_sys_time *wst2)
{ {
#ifdef TIMER_GETTIMEOFDAY #ifdef TIMER_GETTIMEOFDAY
return ((wst1->tv_sec - wst2->tv_sec) * 1000 return ((double)(wst1->tv_sec - wst2->tv_sec) * 1000
+ (wst1->tv_usec - wst2->tv_usec) / 1000); + (double)(wst1->tv_usec - wst2->tv_usec) / 1000);
#endif #endif
#ifdef TIMER_TIME #ifdef TIMER_TIME
@ -1637,7 +1637,7 @@ wtimer_sys_diff (wget_sys_time *wst1, wget_sys_time *wst2)
#endif #endif
#ifdef WINDOWS #ifdef WINDOWS
return (long)(wst1->QuadPart - wst2->QuadPart) / 10000; return (double)(wst1->QuadPart - wst2->QuadPart) / 10000;
#endif #endif
} }
@ -1645,11 +1645,11 @@ wtimer_sys_diff (wget_sys_time *wst1, wget_sys_time *wst2)
reset. It is allowed to call this function more than once to get reset. It is allowed to call this function more than once to get
increasingly higher elapsed values. */ increasingly higher elapsed values. */
long double
wtimer_elapsed (struct wget_timer *wt) wtimer_elapsed (struct wget_timer *wt)
{ {
wget_sys_time now; wget_sys_time now;
long elapsed; double elapsed;
wtimer_sys_set (&now); wtimer_sys_set (&now);
elapsed = wt->elapsed_pre_start + wtimer_sys_diff (&now, &wt->start); elapsed = wt->elapsed_pre_start + wtimer_sys_diff (&now, &wt->start);
@ -1678,18 +1678,18 @@ wtimer_elapsed (struct wget_timer *wt)
return elapsed; return elapsed;
} }
/* Return the assessed granularity of the timer implementation. This /* Return the assessed granularity of the timer implementation, in
is important for certain code that tries to deal with "zero" time milliseconds. This is important for certain code that tries to
intervals. */ deal with "zero" time intervals. */
long double
wtimer_granularity (void) wtimer_granularity (void)
{ {
#ifdef TIMER_GETTIMEOFDAY #ifdef TIMER_GETTIMEOFDAY
/* Granularity of gettimeofday is hugely architecture-dependent. /* Granularity of gettimeofday is hugely architecture-dependent.
However, it appears that on modern machines it is better than However, it appears that on modern machines it is better than
1ms. */ 1ms. Assume 100 usecs. */
return 1; return 0.1;
#endif #endif
#ifdef TIMER_TIME #ifdef TIMER_TIME
@ -1698,7 +1698,7 @@ wtimer_granularity (void)
#endif #endif
#ifdef TIMER_WINDOWS #ifdef TIMER_WINDOWS
/* ? */ /* #### Fill this in! */
return 1; return 1;
#endif #endif
} }

View File

@ -109,8 +109,8 @@ struct wget_timer *wtimer_allocate PARAMS ((void));
struct wget_timer *wtimer_new PARAMS ((void)); struct wget_timer *wtimer_new PARAMS ((void));
void wtimer_delete PARAMS ((struct wget_timer *)); void wtimer_delete PARAMS ((struct wget_timer *));
void wtimer_reset PARAMS ((struct wget_timer *)); void wtimer_reset PARAMS ((struct wget_timer *));
long wtimer_elapsed PARAMS ((struct wget_timer *)); double wtimer_elapsed PARAMS ((struct wget_timer *));
long wtimer_granularity PARAMS ((void)); double wtimer_granularity PARAMS ((void));
char *html_quote_string PARAMS ((const char *)); char *html_quote_string PARAMS ((const char *));

View File

@ -157,23 +157,42 @@ char *xstrdup_debug PARAMS ((const char *, const char *, int));
/* The smaller value of the two. */ /* The smaller value of the two. */
#define MINVAL(x, y) ((x) < (y) ? (x) : (y)) #define MINVAL(x, y) ((x) < (y) ? (x) : (y))
/* Convert the ASCII character X to a hex-digit. X should be between /* Convert the ASCII character that represents a hexadecimal digit to
'0' and '9', or between 'A' and 'F', or between 'a' and 'f'. The the number in range [0, 16) that corresponds to the digit. X
result is a number between 0 and 15. If X is not a hexadecimal should be between '0' and '9', or between 'A' and 'F', or between
digit character, the result is undefined. */ 'a' and 'f'. If X is not a hexadecimal digit character, the result
is undefined. */
#define XCHAR_TO_XDIGIT(x) \ #define XCHAR_TO_XDIGIT(x) \
(((x) >= '0' && (x) <= '9') ? \ (((x) >= '0' && (x) <= '9') ? ((x) - '0') : (TOUPPER(x) - 'A' + 10))
((x) - '0') : (TOUPPER(x) - 'A' + 10))
/* The reverse of the above: convert a HEX digit in the [0, 15] range /* The reverse of the above: convert a digit number in the [0, 16)
to an ASCII character representing it. The A-F characters are range to an ASCII character. The A-F characters are in upper
always in upper case. */ case. */
#define XDIGIT_TO_XCHAR(x) (((x) < 10) ? ((x) + '0') : ((x) - 10 + 'A')) #define XDIGIT_TO_XCHAR(x) ("0123456789ABCDEF"[x])
/* Like XDIGIT_TO_XCHAR, but produce a lower-case char. */ /* Like XDIGIT_TO_XCHAR, but generates lower-case characters. */
#define XDIGIT_TO_xchar(x) (((x) < 10) ? ((x) + '0') : ((x) - 10 + 'a')) #define XDIGIT_TO_xchar(x) ("0123456789abcdef"[x])
#define ARRAY_SIZE(array) (sizeof (array) / sizeof (*(array))) /* Returns the number of elements in an array with fixed
initialization. For example:
static char a[] = "foo"; -- countof(a) == 4 (for terminating \0)
int a[5] = {1, 2}; -- countof(a) == 5
char *a[3] = { -- countof(a) == 3
"foo", "bar", "baz"
};
And, most importantly, it works when the compiler counts the array
elements for you:
char *a[] = { -- countof(a) == 4
"foo", "bar", "baz", "qux"
} */
#define countof(array) (sizeof (array) / sizeof (*(array)))
#define ARRAY_SIZE(array) countof (array)
/* Copy the data delimited with BEG and END to alloca-allocated /* Copy the data delimited with BEG and END to alloca-allocated
storage, and zero-terminate it. BEG and END are evaluated only storage, and zero-terminate it. BEG and END are evaluated only