git: 9front

Download patch

ref: ecc0bbf84566b70b8cee3ee4cbda57c10e635196
parent: a2b9a9d62f20e77229b1189e70a68dfcc6806ef1
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Sun Aug 11 04:31:53 EDT 2013

libdraw: make ebread() return buffer immidiately if available, cleanup

this reduces number of syscalls and improves performance for vt

--- a/sys/src/libdraw/event.c
+++ b/sys/src/libdraw/event.c
@@ -45,21 +45,10 @@
 ebread(Slave *s)
 {
 	Ebuf *eb;
-	Dir *d;
-	ulong l;
-
-	for(;;){
-		d = dirfstat(epipe[0]);
-		if(d == nil)
-			drawerror(display, "events: eread stat error");
-		l = d->length;
-		free(d);
-		if(s->head && l==0)
-			break;
+ 
+	while((eb = s->head) == 0)
 		extract();
-	}
-	eb = s->head;
-	s->head = s->head->next;
+	s->head = eb->next;
 	if(s->head == 0)
 		s->tail = 0;
 	return eb;
@@ -322,9 +311,10 @@
 	memmove(eb->buf, &ebuf[1], n - 1);
 	eb->next = 0;
 	if(s->head)
-		s->tail = s->tail->next = eb;
+		s->tail->next = eb;
 	else
-		s->head = s->tail = eb;
+		s->head = eb;
+	s->tail = eb;
 }
 
 static int
--