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:
parent
016867ca33
commit
ea8a108b1f
@ -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>
|
||||
|
||||
* cookies.c (parse_set_cookies): Fixed the parser to handle more
|
||||
|
30
src/utils.c
30
src/utils.c
@ -1551,11 +1551,11 @@ struct wget_timer {
|
||||
|
||||
/* The most recent elapsed time, calculated by wtimer_elapsed().
|
||||
Measured in milliseconds. */
|
||||
long elapsed_last;
|
||||
double elapsed_last;
|
||||
|
||||
/* Approximately, the time elapsed between the true start of the
|
||||
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
|
||||
@ -1624,12 +1624,12 @@ wtimer_reset (struct wget_timer *wt)
|
||||
wt->elapsed_pre_start = 0;
|
||||
}
|
||||
|
||||
static long
|
||||
static double
|
||||
wtimer_sys_diff (wget_sys_time *wst1, wget_sys_time *wst2)
|
||||
{
|
||||
#ifdef TIMER_GETTIMEOFDAY
|
||||
return ((wst1->tv_sec - wst2->tv_sec) * 1000
|
||||
+ (wst1->tv_usec - wst2->tv_usec) / 1000);
|
||||
return ((double)(wst1->tv_sec - wst2->tv_sec) * 1000
|
||||
+ (double)(wst1->tv_usec - wst2->tv_usec) / 1000);
|
||||
#endif
|
||||
|
||||
#ifdef TIMER_TIME
|
||||
@ -1637,7 +1637,7 @@ wtimer_sys_diff (wget_sys_time *wst1, wget_sys_time *wst2)
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS
|
||||
return (long)(wst1->QuadPart - wst2->QuadPart) / 10000;
|
||||
return (double)(wst1->QuadPart - wst2->QuadPart) / 10000;
|
||||
#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
|
||||
increasingly higher elapsed values. */
|
||||
|
||||
long
|
||||
double
|
||||
wtimer_elapsed (struct wget_timer *wt)
|
||||
{
|
||||
wget_sys_time now;
|
||||
long elapsed;
|
||||
double elapsed;
|
||||
|
||||
wtimer_sys_set (&now);
|
||||
elapsed = wt->elapsed_pre_start + wtimer_sys_diff (&now, &wt->start);
|
||||
@ -1678,18 +1678,18 @@ wtimer_elapsed (struct wget_timer *wt)
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
/* Return the assessed granularity of the timer implementation. This
|
||||
is important for certain code that tries to deal with "zero" time
|
||||
intervals. */
|
||||
/* Return the assessed granularity of the timer implementation, in
|
||||
milliseconds. This is important for certain code that tries to
|
||||
deal with "zero" time intervals. */
|
||||
|
||||
long
|
||||
double
|
||||
wtimer_granularity (void)
|
||||
{
|
||||
#ifdef TIMER_GETTIMEOFDAY
|
||||
/* Granularity of gettimeofday is hugely architecture-dependent.
|
||||
However, it appears that on modern machines it is better than
|
||||
1ms. */
|
||||
return 1;
|
||||
1ms. Assume 100 usecs. */
|
||||
return 0.1;
|
||||
#endif
|
||||
|
||||
#ifdef TIMER_TIME
|
||||
@ -1698,7 +1698,7 @@ wtimer_granularity (void)
|
||||
#endif
|
||||
|
||||
#ifdef TIMER_WINDOWS
|
||||
/* ? */
|
||||
/* #### Fill this in! */
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
@ -109,8 +109,8 @@ struct wget_timer *wtimer_allocate PARAMS ((void));
|
||||
struct wget_timer *wtimer_new PARAMS ((void));
|
||||
void wtimer_delete PARAMS ((struct wget_timer *));
|
||||
void wtimer_reset PARAMS ((struct wget_timer *));
|
||||
long wtimer_elapsed PARAMS ((struct wget_timer *));
|
||||
long wtimer_granularity PARAMS ((void));
|
||||
double wtimer_elapsed PARAMS ((struct wget_timer *));
|
||||
double wtimer_granularity PARAMS ((void));
|
||||
|
||||
char *html_quote_string PARAMS ((const char *));
|
||||
|
||||
|
45
src/wget.h
45
src/wget.h
@ -157,23 +157,42 @@ char *xstrdup_debug PARAMS ((const char *, const char *, int));
|
||||
/* The smaller value of the two. */
|
||||
#define MINVAL(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
/* Convert the ASCII character X to a hex-digit. X should be between
|
||||
'0' and '9', or between 'A' and 'F', or between 'a' and 'f'. The
|
||||
result is a number between 0 and 15. If X is not a hexadecimal
|
||||
digit character, the result is undefined. */
|
||||
/* Convert the ASCII character that represents a hexadecimal digit to
|
||||
the number in range [0, 16) that corresponds to the digit. X
|
||||
should be between '0' and '9', or between 'A' and 'F', or between
|
||||
'a' and 'f'. If X is not a hexadecimal digit character, the result
|
||||
is undefined. */
|
||||
#define XCHAR_TO_XDIGIT(x) \
|
||||
(((x) >= '0' && (x) <= '9') ? \
|
||||
((x) - '0') : (TOUPPER(x) - 'A' + 10))
|
||||
(((x) >= '0' && (x) <= '9') ? ((x) - '0') : (TOUPPER(x) - 'A' + 10))
|
||||
|
||||
/* The reverse of the above: convert a HEX digit in the [0, 15] range
|
||||
to an ASCII character representing it. The A-F characters are
|
||||
always in upper case. */
|
||||
#define XDIGIT_TO_XCHAR(x) (((x) < 10) ? ((x) + '0') : ((x) - 10 + 'A'))
|
||||
/* The reverse of the above: convert a digit number in the [0, 16)
|
||||
range to an ASCII character. The A-F characters are in upper
|
||||
case. */
|
||||
#define XDIGIT_TO_XCHAR(x) ("0123456789ABCDEF"[x])
|
||||
|
||||
/* Like XDIGIT_TO_XCHAR, but produce a lower-case char. */
|
||||
#define XDIGIT_TO_xchar(x) (((x) < 10) ? ((x) + '0') : ((x) - 10 + 'a'))
|
||||
/* Like XDIGIT_TO_XCHAR, but generates lower-case characters. */
|
||||
#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
|
||||
storage, and zero-terminate it. BEG and END are evaluated only
|
||||
|
Loading…
Reference in New Issue
Block a user