shithub: pplay

Download patch

ref: f3c2b5940936fd886f55a3b2afb527cc7cb38a9a
parent: db9fa8f96c3d429644cf4f28621687975eea41ed
author: qwx <qwx@sciops.net>
date: Thu Dec 8 17:16:42 EST 2022

reimplement advance() using getslice()

--- a/cmd.c
+++ b/cmd.c
@@ -310,33 +310,19 @@
 	return b - buf;
 }
 
-void
+int
 advance(Dot *d, usize n)
 {
-	usize Δ, Δbuf, Δloop, m, off;
-	Chunk *c;
+	usize m, sz;
 
-	c = p2c(d->pos, &off);
-	m = n;
-	while(m > 0){
-		Δloop = d->to.pos - d->pos;
-		Δbuf = c->bufsz - off;
-		if(m < Δloop && m < Δbuf){
-			d->pos += m;
-			break;
-		}else if(Δloop < Δbuf){
-			Δ = Δloop;
-			d->pos = d->from.pos;
-			c = p2c(d->from.pos, nil);
-			off = 0;
-		}else{
-			Δ = Δbuf;
-			d->pos += Δ;
-			c = c->right;
-			off = 0;
-		}
-		m -= Δ;
+	m = 0;
+	while(n > 0){
+		if(getslice(d, n, &sz) == nil)
+			return -1;
+		m += sz;
+		n -= sz;
 	}
+	return m;
 }
 
 static int
@@ -515,7 +501,6 @@
 	static usize bufsz;
 	int nio;
 	usize n, m, c, k;
-	uchar *p;
 	Dot d;
 
 	d.pos = d.from.pos = dot.from.pos;
--- a/fns.h
+++ b/fns.h
@@ -9,7 +9,7 @@
 void	setjump(usize);
 void	redraw(int);
 void	initdrw(void);
-void	advance(Dot*, usize);
+int	advance(Dot*, usize);
 int	jump(usize);
 Chunk*	p2c(usize, usize*);
 void	setrange(usize, usize);