[Circle] [CODE] Search buffering

From: Sammy (samedi@clark.net)
Date: 08/24/96


In case anybody else out there is stuck on a terribly slow server and 
have noticed zone reset lag (I've seen a certain zone take 2-3 minutes to 
reset during busy hours), here's a simple fix to speed things up a little.
All it does is buffer the last mob, object, and room so if you load the 
same mob twice it doesn't search the whole index again.

Add these three variables to db.c somewhere around the top:

/* search buffereing */
sh_int mob_sbuf = NOBODY;
sh_int obj_sbuf = NOTHING;
sh_int room_sbuf = NOWHERE;

And replace real_room, real_object, and real_mobile with these (if anyone 
out there is still using obuild just change the xxx_sbuf parts).  PLease 
excuse any typos.  If there's trouble just copy the buffering lines.

Sam

int real_room(int virtual)
{
  int bot, top, mid;

  bot = 0;
  top = top_of_world;

  if((world + room_sbuf)->number == virtual)
    return room_sbuf;

  for (;;) {
    mid = (bot + top) >> 1;

    if ((world + mid)->number == virtual) {
      room_sbuf = mid;
      return mid;
    }
    if (bot >= top)
      break;
    if ((world + mid)->number > virtual)
      top = mid - 1;
    else
      bot = mid + 1;
  }

  return(NOWHERE);
}

int real_mobile(int virtual)
{
  int bot, top, mid;

  bot = 0;
  top = top_of_mobt;

  if((mob_index + mob_sbuf)->virtual == virtual)
    return mob_sbuf;

  for (;;) {
    mid = (bot + top) >> 1;

    if ((mob_index + mid)->virtual == virtual) {
      mob_sbuf = mid;
      return mid;
    }
    if (bot >= top)
      break;
    if ((mob_index + mid)->virtual > virtual)
      top = mid - 1;
    else
      bot = mid + 1;
  }

  return(NOBODY);
}

int real_object(int virtual)
{
  int bot, top, mid;

  bot = 0;
  top = top_of_objt;

  if((obj_index + obj_sbuf)->virtual == virtual)
    return obj_sbuf;

  for (;;) {
    mid = (bot + top) >> 1;

    if ((obj_index + mid)->virtual == virtual) {
      obj_sbuf = mid;
      return mid;
    }
    if (bot >= top)
      break;
    if ((obj_index + mid)->virtual > virtual)
      top = mid - 1;
    else
      bot = mid + 1;
  }

  return(NOTHING);
}

+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/07/00 PST