Changeset 801b7ac


Ignore:
Timestamp:
Feb 6, 2007, 6:05:13 PM (17 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
7a20e4c
Parents:
2566560
Message:
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.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    r0331c8f r801b7ac  
    239239      fg = f->fgcolorbuff[position];
    240240      bg = f->bgcolorbuff[position];
    241       owl_function_debugmsg("waddstr: fg(%i) bg(%i).", fg, bg);
    242241
    243242      pair = owl_fmtext_get_colorpair(fg, bg);
     
    696695{
    697696  owl_colorpair_mgr *cpmgr;
    698   short pair, i, default_bg;
     697  short pair, default_bg;
    699698
    700699#ifdef HAVE_USE_DEFAULT_COLORS
  • functions.c

    r29ebcea r801b7ac  
    12731273int owl_function_calculate_topmsg_normal(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines)
    12741274{
    1275   int savey, j, i, foo, y;
     1275  int savey, i, foo, y;
    12761276
    12771277  if (curmsg<0) return(topmsg);
     
    12821282  }
    12831283
    1284   /* Find number of lines from top to bottom of curmsg (store in savey) */
    1285   savey=0;
    1286   for (i=topmsg; i<=curmsg; i++) {
    1287     savey+=owl_message_get_numlines(owl_view_get_element(v, i));
     1284  /* If curmsg is so far past topmsg that there are more messages than
     1285     lines, skip the line counting that follows because we're
     1286     certainly off screen.  */
     1287  savey=curmsg-topmsg;
     1288  if (savey <= recwinlines) {
     1289    /* Find number of lines from top to bottom of curmsg (store in savey) */
     1290    savey = 0;
     1291    for (i=topmsg; i<=curmsg; i++) {
     1292      savey+=owl_message_get_numlines(owl_view_get_element(v, i));
     1293    }
    12881294  }
    12891295
     
    12921298  if (savey > recwinlines) {
    12931299    topmsg=curmsg;
    1294     savey=owl_message_get_numlines(owl_view_get_element(v, i));
     1300    savey=owl_message_get_numlines(owl_view_get_element(v, curmsg));
    12951301    direction=OWL_DIRECTION_UPWARDS;
    12961302  }
     
    13001306    if (savey < (recwinlines / 4)) {
    13011307      y=0;
    1302       for (j=curmsg; j>=0; j--) {
    1303         foo=owl_message_get_numlines(owl_view_get_element(v, j));
     1308      for (i=curmsg; i>=0; i--) {
     1309        foo=owl_message_get_numlines(owl_view_get_element(v, i));
    13041310        /* will we run the curmsg off the screen? */
    13051311        if ((foo+y) >= recwinlines) {
    1306           j++;
    1307           if (j>curmsg) j=curmsg;
     1312          i++;
     1313          if (i>curmsg) i=curmsg;
    13081314          break;
    13091315        }
     
    13121318        if (y > (recwinlines / 2)) break;
    13131319      }
    1314       if (j<0) j=0;
    1315       return(j);
     1320      if (i<0) i=0;
     1321      return(i);
    13161322    }
    13171323  }
     
    13221328      y=0;
    13231329      /* count lines from the top until we can save 1/2 the screen size */
    1324       for (j=topmsg; j<curmsg; j++) {
    1325         y+=owl_message_get_numlines(owl_view_get_element(v, j));
     1330      for (i=topmsg; i<curmsg; i++) {
     1331        y+=owl_message_get_numlines(owl_view_get_element(v, i));
    13261332        if (y > (recwinlines / 2)) break;
    13271333      }
    1328       if (j==curmsg) {
    1329         j--;
     1334      if (i==curmsg) {
     1335        i--;
    13301336      }
    1331       return(j+1);
     1337      return(i+1);
    13321338    }
    13331339  }
  • view.c

    rf1e629d r801b7ac  
    9797int owl_view_get_nearest_to_msgid(owl_view *v, int targetid)
    9898{
    99   int i, bestdist=-1, bestpos=0, curid, curdist;
     99  int first, last, mid = 0, max, bestdist, curid = 0;
    100100
    101   for (i=0; i<owl_view_get_size(v); i++) {
    102     curid = owl_message_get_id(owl_view_get_element(v, i));
    103     curdist = abs(targetid-curid);
    104     if (bestdist<0 || curdist<bestdist) {
    105       bestdist = curdist;
    106       bestpos = i;
     101  first = 0;
     102  last = max = owl_view_get_size(v) - 1;
     103  while (first <= last) {
     104    mid = (first + last) / 2;
     105    curid = owl_message_get_id(owl_view_get_element(v, mid));
     106    if (curid == targetid) {
     107      return(mid);
     108    } else if (curid < targetid) {
     109      first = mid + 1;
     110    } else {
     111      last = mid - 1;
    107112    }
    108113  }
    109   return (bestpos);
     114  bestdist = abs(targetid-curid);
     115  if (curid < targetid && mid+1 < max) {
     116    curid = owl_message_get_id(owl_view_get_element(v, mid+1));
     117    mid = (bestdist < abs(targetid-curid)) ? mid : mid+1;
     118  }
     119  else if (curid > targetid && mid-1 >= 0) {
     120    curid = owl_message_get_id(owl_view_get_element(v, mid-1));
     121    mid = (bestdist < abs(targetid-curid)) ? mid : mid-1;
     122  }
     123  return mid;
    110124}
    111125
Note: See TracChangeset for help on using the changeset viewer.