[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
clarify width_to_bytes
From: |
Ben Pfaff |
Subject: |
clarify width_to_bytes |
Date: |
Wed, 20 Sep 2006 19:44:30 -0700 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) |
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
- clarify width_to_bytes,
Ben Pfaff <=