Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Aug 2008 22:34:43 GMT
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 148753 for review
Message-ID:  <200808282234.m7SMYh8C098414@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=148753

Change 148753 by gabor@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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808282234.m7SMYh8C098414>