pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: clarify width_to_bytes


From: John Darrington
Subject: Re: clarify width_to_bytes
Date: Thu, 21 Sep 2006 18:16:54 +0800
User-agent: Mutt/1.5.4i

That seems to make sense to me.

I remember I had to make all sorts of on-the-fly changes to that
function, when I was trying to second guess the way that spss had
implemented very long strings.


I should have looked at it again after I'd finished the job.

J'



On Wed, Sep 20, 2006 at 07:44:30PM -0700, Ben Pfaff wrote:
     In the midst of working on system file stuff, I noticed that
     width_to_bytes in src/data/variable.c is more complex than
     needed.  I'd like to check in the following change to make its
     operation clearer.  Comments?
     
     Index: variable.c
     ===================================================================
     RCS file: /cvsroot/pspp/pspp/src/data/variable.c,v
     retrieving revision 1.9
     diff -u -p -u -p -r1.9 variable.c
     --- variable.c     8 Jul 2006 03:05:51 -0000       1.9
     +++ variable.c     21 Sep 2006 02:42:18 -0000
     @@ -356,30 +358,19 @@ dict_class_to_name (enum dict_class dict
      int
      width_to_bytes(int width)
      {
     -  const int chunks = width / EFFECTIVE_LONG_STRING_LENGTH ;
     -  const int remainder = width - (chunks * EFFECTIVE_LONG_STRING_LENGTH) ;
     -  int bytes, mod8;
     -
        assert (width >= 0);
      
        if ( width == 0 ) 
          return MAX_SHORT_STRING ;
     -
     -  if ( width <= MAX_LONG_STRING) 
     -    return MAX_SHORT_STRING * DIV_RND_UP(width, MAX_SHORT_STRING);
     -
     -
     -  bytes =  remainder + (chunks * (MAX_LONG_STRING + 1) );
     -
     -  /* Round up to the nearest 8 */
     -  mod8 = bytes % MAX_SHORT_STRING;
     -
     -  if ( mod8 ) 
     -    bytes += MAX_SHORT_STRING - mod8;
     -
     -  assert( bytes % MAX_SHORT_STRING == 0 );
     -
     -  return bytes;
     +  else if (width <= MAX_LONG_STRING) 
     +    return ROUND_UP (width, MAX_SHORT_STRING);
     +  else 
     +    {
     +      int chunks = width / EFFECTIVE_LONG_STRING_LENGTH ;
     +      int remainder = width % EFFECTIVE_LONG_STRING_LENGTH ;
     +      int bytes = remainder + (chunks * (MAX_LONG_STRING + 1) );
     +      return ROUND_UP (bytes, MAX_SHORT_STRING); 
     +    }
      }
      
      
     
     
     -- 
     Ben Pfaff 
     email: address@hidden
     web: http://benpfaff.org
     
     
     _______________________________________________
     pspp-dev mailing list
     address@hidden
     http://lists.gnu.org/mailman/listinfo/pspp-dev

-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.


Attachment: pgpbasWZDMzt7.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]