Thread View: news.software.nntp
1 messages
1 total messages
Started by David Robinson
Thu, 13 Jul 1989 03:16
ihave speedup
Author: David Robinson
Date: Thu, 13 Jul 1989 03:16
Date: Thu, 13 Jul 1989 03:16
129 lines
3856 bytes
3856 bytes
Below is a noticeable speedup in the processing of IHAVE requests,
especially if you receive many duplicates.
In the function ihave(), gethistent() is called to see if
the proposed article exists if it returns non-NULL a "Got It"
message is sent back, otherwise the article is accepted. No
where is the value returned (the path of the article) ever used
by ihave().
In gethistent(), a database lookup is performed and the resulting
value is used to seek into the history file and then read the
line. Since ihave() doesn't really need the path, the extra lseek()
and fgets() (which usually forces a hard disk read) is wasted.
These diffs add a lookup variable as an argument to gethistent,
it it is non-zero only a history lookup is performed and a bogus
non-NULL pointer is returned.
Gethistent should probably be rewritten into two pieces, one part
to get back the database value and the other to actually read the
history file.
I also noticed a rewind() that is done on the history file right
before the fseek() to an absolute offset. I see no good reason to
do this and it has the side effect of flushing the stdio input
buffer.
-David Robinson
==================
*** misc.c-orig Wed Jun 14 19:32:32 1989
--- misc.c Wed Jul 12 20:09:46 1989
***************
*** 72,77 ****
--- 72,78 ----
*
* Parameters: "msg_id" is the message ID of the
* article, enclosed in <>'s.
+ * "lookup", only check if article exists
*
* Returns: A char pointer to a static data area
* containing the full pathname of the
***************
*** 91,98 ****
#endif not DBM
char *
! gethistent(msg_id)
char *msg_id;
{
char line[MAXBUFLEN];
char *tmp;
--- 92,100 ----
#endif not DBM
char *
! gethistent(msg_id, lookup)
char *msg_id;
+ int lookup;
{
char line[MAXBUFLEN];
char *tmp;
***************
*** 167,172 ****
--- 169,181 ----
if (content.dptr == NULL)
return (NULL);
+ /*
+ * If we are just checking to see if it exists return a non-NULL
+ * result
+ */
+ if (lookup)
+ return ((char *)1);
+
if (hfp == NULL) {
hfp = fopen(historyfile, "r");
if (hfp == NULL) {
***************
*** 177,182 ****
--- 186,192 ----
return (NULL);
}
} else {
+ /* Why do this if we are going to do an absolute fseek below? XXX */
rewind(hfp);
}
***************
*** 241,247 ****
{
char *path;
! path = gethistent(msg_id);
if (path != NULL)
return (fopen(path, "r"));
else
--- 251,257 ----
{
char *path;
! path = gethistent(msg_id, 0);
if (path != NULL)
return (fopen(path, "r"));
else
*** ihave.c-orig Wed Jun 14 19:32:32 1989
--- ihave.c Mon Jul 10 20:00:46 1989
***************
*** 30,36 ****
return;
}
! cp = gethistent(argv[1]);
if (cp != NULL) {
printf("%d Got it.\r\n", ERR_GOTIT);
(void) fflush(stdout);
--- 30,36 ----
return;
}
! cp = gethistent(argv[1], 1);
if (cp != NULL) {
printf("%d Got it.\r\n", ERR_GOTIT);
(void) fflush(stdout);
--
David Robinson elroy!david@csvax.caltech.edu ARPA
david@elroy.jpl.nasa.gov ARPA
{cit-vax,ames}!elroy!david UUCP
Disclaimer: No one listens to me anyway!
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads