Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
orkinCompare.h File Reference
#include "mdb.h"
#include "mork.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  orkinCompare

Functions

mdb_order mdbYarn_Order (const mdbYarn *inSelf, morkEnv *ev, const mdbYarn *inSecond)

Function Documentation

mdb_order mdbYarn_Order ( const mdbYarn inSelf,
morkEnv ev,
const mdbYarn inSecond 
)

Definition at line 68 of file orkinCompare.cpp.

{
  // This code is a close copy of public domain Mithril's AgYarn_CompareLen().
  // Note all comments are from the original public domain Mithril code.
  
  mork_u1* self = (mork_u1*) inSelf->mYarn_Buf;
  mork_u1* yarn = (mork_u1*) inYarn->mYarn_Buf;
  
  mdb_fill selfFill = inSelf->mYarn_Fill;
  mdb_fill yarnFill = inYarn->mYarn_Fill;
  
  if ( selfFill && yarnFill ) /* neither yarn is empty? */
  {
    register int a; /* a byte from self */
    register int b; /* a byte from yarn */
    
    /* predecrement is normally used in loop tests to minimize instructions: */
    ++selfFill; /* prepare for predecrement */
    ++yarnFill; /* prepare for predecrement */
    /* we check only self len at loop top, but yarn len check must follow: */
    
    while ( --selfFill ) /* another byte in self? */
    {
      if ( !--yarnFill ) /* yarn runs out first? self is greater (pos)? */
        return 1;
      
      b = (mork_u1) *yarn++;  /* next byte in other yarn */
      a = (mork_u1) *self++;  /* next byte in self yarn */

      if ( a != b ) /* found first different byte? */
        return ( a - b ); /* return relative order */
    }
    /* if remaining yarn len is exactly 1, it runs out at same time as self: */
    return ( yarnFill == 1 )? 0 : -1; /* yarn is same len? or self is less? */
  }
  else
    return ((mdb_order) selfFill) - ((mdb_order) yarnFill);
}

Here is the caller graph for this function: