[457] in BarnOwl Developers
[D-O-H] r586 - trunk/owl
daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:06:22 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Tue, 6 Feb 2007 18:05:14 -0500 (EST)
Author: asedeno
Date: 2007-02-06 18:05:13 -0500 (Tue, 06 Feb 2007)
New Revision: 586
Modified:
trunk/owl/fmtext.c
trunk/owl/functions.c
trunk/owl/view.c
Log:
functions.c: tweak owl_function_calculate_topmsg_normal to not suck as
much. This resolves the delay in jumping from the first message to the
last message.
fmtext.c: get rid of a debug message and an unused variable.
view.c: Convert another linear search to binary search.
Modified: trunk/owl/fmtext.c
===================================================================
--- trunk/owl/fmtext.c 2007-02-06 21:40:41 UTC (rev 585)
+++ trunk/owl/fmtext.c 2007-02-06 23:05:13 UTC (rev 586)
@@ -238,7 +238,6 @@
short pair;
fg = f->fgcolorbuff[position];
bg = f->bgcolorbuff[position];
- owl_function_debugmsg("waddstr: fg(%i) bg(%i).", fg, bg);
pair = owl_fmtext_get_colorpair(fg, bg);
if (pair != -1) {
@@ -695,7 +694,7 @@
short owl_fmtext_get_colorpair(int fg, int bg)
{
owl_colorpair_mgr *cpmgr;
- short pair, i, default_bg;
+ short pair, default_bg;
#ifdef HAVE_USE_DEFAULT_COLORS
if (fg == OWL_COLOR_DEFAULT) fg = -1;
Modified: trunk/owl/functions.c
===================================================================
--- trunk/owl/functions.c 2007-02-06 21:40:41 UTC (rev 585)
+++ trunk/owl/functions.c 2007-02-06 23:05:13 UTC (rev 586)
@@ -1272,7 +1272,7 @@
int owl_function_calculate_topmsg_normal(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines)
{
- int savey, j, i, foo, y;
+ int savey, i, foo, y;
if (curmsg<0) return(topmsg);
@@ -1281,17 +1281,23 @@
topmsg=owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines);
}
- /* Find number of lines from top to bottom of curmsg (store in savey) */
- savey=0;
- for (i=topmsg; i<=curmsg; i++) {
- savey+=owl_message_get_numlines(owl_view_get_element(v, i));
+ /* If curmsg is so far past topmsg that there are more messages than
+ lines, skip the line counting that follows because we're
+ certainly off screen. */
+ savey=curmsg-topmsg;
+ if (savey <= recwinlines) {
+ /* Find number of lines from top to bottom of curmsg (store in savey) */
+ savey = 0;
+ for (i=topmsg; i<=curmsg; i++) {
+ savey+=owl_message_get_numlines(owl_view_get_element(v, i));
+ }
}
/* If we're off the bottom of the screen, set the topmsg to curmsg
* and scroll upwards */
if (savey > recwinlines) {
topmsg=curmsg;
- savey=owl_message_get_numlines(owl_view_get_element(v, i));
+ savey=owl_message_get_numlines(owl_view_get_element(v, curmsg));
direction=OWL_DIRECTION_UPWARDS;
}
@@ -1299,20 +1305,20 @@
if (direction == OWL_DIRECTION_UPWARDS || direction == OWL_DIRECTION_NONE) {
if (savey < (recwinlines / 4)) {
y=0;
- for (j=curmsg; j>=0; j--) {
- foo=owl_message_get_numlines(owl_view_get_element(v, j));
+ for (i=curmsg; i>=0; i--) {
+ foo=owl_message_get_numlines(owl_view_get_element(v, i));
/* will we run the curmsg off the screen? */
if ((foo+y) >= recwinlines) {
- j++;
- if (j>curmsg) j=curmsg;
+ i++;
+ if (i>curmsg) i=curmsg;
break;
}
/* have saved 1/2 the screen space? */
y+=foo;
if (y > (recwinlines / 2)) break;
}
- if (j<0) j=0;
- return(j);
+ if (i<0) i=0;
+ return(i);
}
}
@@ -1321,14 +1327,14 @@
if (savey > ((recwinlines * 3)/4)) {
y=0;
/* count lines from the top until we can save 1/2 the screen size */
- for (j=topmsg; j<curmsg; j++) {
- y+=owl_message_get_numlines(owl_view_get_element(v, j));
+ for (i=topmsg; i<curmsg; i++) {
+ y+=owl_message_get_numlines(owl_view_get_element(v, i));
if (y > (recwinlines / 2)) break;
}
- if (j==curmsg) {
- j--;
+ if (i==curmsg) {
+ i--;
}
- return(j+1);
+ return(i+1);
}
}
Modified: trunk/owl/view.c
===================================================================
--- trunk/owl/view.c 2007-02-06 21:40:41 UTC (rev 585)
+++ trunk/owl/view.c 2007-02-06 23:05:13 UTC (rev 586)
@@ -96,17 +96,31 @@
* to the passed msgid. */
int owl_view_get_nearest_to_msgid(owl_view *v, int targetid)
{
- int i, bestdist=-1, bestpos=0, curid, curdist;
+ int first, last, mid = 0, max, bestdist, curid = 0;
- for (i=0; i<owl_view_get_size(v); i++) {
- curid = owl_message_get_id(owl_view_get_element(v, i));
- curdist = abs(targetid-curid);
- if (bestdist<0 || curdist<bestdist) {
- bestdist = curdist;
- bestpos = i;
+ first = 0;
+ last = max = owl_view_get_size(v) - 1;
+ while (first <= last) {
+ mid = (first + last) / 2;
+ curid = owl_message_get_id(owl_view_get_element(v, mid));
+ if (curid == targetid) {
+ return(mid);
+ } else if (curid < targetid) {
+ first = mid + 1;
+ } else {
+ last = mid - 1;
}
}
- return (bestpos);
+ bestdist = abs(targetid-curid);
+ if (curid < targetid && mid+1 < max) {
+ curid = owl_message_get_id(owl_view_get_element(v, mid+1));
+ mid = (bestdist < abs(targetid-curid)) ? mid : mid+1;
+ }
+ else if (curid > targetid && mid-1 >= 0) {
+ curid = owl_message_get_id(owl_view_get_element(v, mid-1));
+ mid = (bestdist < abs(targetid-curid)) ? mid : mid-1;
+ }
+ return mid;
}
int owl_view_get_nearest_to_saved(owl_view *v)