PERFORCE change 148753 for review
Gabor Kovesdan
gabor at FreeBSD.org
Thu Aug 28 22:34:43 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=148753
Change 148753 by gabor at gabor_server on 2008/08/28 22:34:22
- Drop unnecessary function
- style(9) and better readable code
- Add a comment about performance
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/grep/queue.c#6 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/grep/queue.c#6 (text+ko) ====
@@ -26,7 +26,7 @@
/*
* A really poor man's queue. It does only what it has to and gets out of
- * Dodge.
+ * Dodge. It is used in place of <sys/queue.h> to get a better performance.
*/
#include <sys/cdefs.h>
@@ -62,23 +62,16 @@
q_head = q_tail = NULL;
}
-static void
-free_item(struct queue *item)
-{
-
- free(item);
-}
-
void
enqueue(struct str *x)
{
struct queue *item;
- item = grep_malloc(sizeof *item + x->len);
+ item = grep_malloc(sizeof(struct queue));
+ item->data.dat = grep_malloc(sizeof(char) * x->len);
item->data.len = x->len;
item->data.line_no = x->line_no;
item->data.off = x->off;
- item->data.dat = (char *)item + sizeof *item;
memcpy(item->data.dat, x->dat, x->len);
item->data.file = x->file;
item->next = NULL;
@@ -91,7 +84,7 @@
}
if (++count > Bflag)
- free_item(dequeue());
+ free(dequeue());
}
static struct queue *
@@ -117,7 +110,7 @@
while ((item = dequeue()) != NULL) {
printline(&item->data, '-', (regmatch_t *)NULL, 0);
- free_item(item);
+ free(item);
}
}
@@ -127,5 +120,5 @@
struct queue *item;
while ((item = dequeue()) != NULL)
- free_item(item);
+ free(item);
}
More information about the p4-projects
mailing list