[PATCH 2/4] libgst: Miscellaneous improving to code style

Lee Duhem <[email protected]>
Newsgroups gmane.comp.lang.smalltalk.gnu.general
Message-ID <[email protected]>
2017-04-26  Lee Duhem  <[email protected]>

      * cint.c: Include ffi.h properly.
      * dict.c (create_classes_pass1): Use INCR_INT.
      (init_c_symbols): Replace magic number with corresponding macro.
      (new_num_fields): Move variable assignment closer to its use.
      (find_key_or_nil): Ditto.
      (_gst_to_wide_cstring): Replace magic number with meaningful
      expression.
      * files.c (_gst_initialize): Simplify code.
      * save.c (save_object): Improve readability of magic number.
---
 libgst/ChangeLog | 12 ++++++++++++
 libgst/cint.c    |  2 +-
 libgst/dict.c    | 14 ++++++--------
 libgst/files.c   |  4 ++--
 libgst/save.c    |  2 +-
 5 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/libgst/ChangeLog b/libgst/ChangeLog
index d8e413c..e876657 100644
--- a/libgst/ChangeLog
+++ b/libgst/ChangeLog
@@ -1,5 +1,17 @@
 2017-04-26  Lee Duhem  <[email protected]>
 
+	* cint.c: Include ffi.h properly.
+	* dict.c (create_classes_pass1): Use INCR_INT.
+	(init_c_symbols): Replace magic number with corresponding macro.
+	(new_num_fields): Move variable assignment closer to its use.
+	(find_key_or_nil): Ditto.
+	(_gst_to_wide_cstring): Replace magic number with meaningful
+	expression.
+	* files.c (_gst_initialize): Simplify code.
+	* save.c (save_object): Improve readability of magic number.
+
+2017-04-26  Lee Duhem  <[email protected]>
+
 	* byte.h: Fix typo in comments.
 	* dict.h: Improve comments.
 	* dict.c (new_num_fields): Ditto.
diff --git a/libgst/cint.c b/libgst/cint.c
index fdb6ce3..6848234 100644
--- a/libgst/cint.c
+++ b/libgst/cint.c
@@ -56,7 +56,7 @@
 #include "re.h"
 #include "pointer-set.h"
 
-#include "ffi.h"
+#include <ffi.h>
 #include <ltdl.h>
 
 #ifdef HAVE_GETGRNAM
diff --git a/libgst/dict.c b/libgst/dict.c
index 517bd5d..9acb44c 100644
--- a/libgst/dict.c
+++ b/libgst/dict.c
@@ -858,8 +858,7 @@ create_classes_pass1 (const class_definition *ci,
       else
 	{
           superclass = (gst_class) OOP_TO_OBJ (superClassOOP);
-          superclass->subClasses =
-	    FROM_INT (TO_INT (superclass->subClasses) + 1);
+          superclass->subClasses = INCR_INT (superclass->subClasses);
 	}
     }
 
@@ -1225,7 +1224,7 @@ init_c_symbols ()
 void
 init_primitives_dictionary ()
 {
-  OOP primDictionaryOOP = _gst_binding_dictionary_new (512, _gst_smalltalk_dictionary);
+  OOP primDictionaryOOP = _gst_binding_dictionary_new (NUM_PRIMITIVES, _gst_smalltalk_dictionary);
   int i;
 
   add_smalltalk ("VMPrimitives", primDictionaryOOP);
@@ -1517,7 +1516,7 @@ new_num_fields (size_t oldNumFields)
 {
   /* Find a power of two that is larger than oldNumFields */
 
-  int n = 1;
+  int n;
 
   /* Already a power of two? duplicate the size */
   if COMMON ((oldNumFields & (oldNumFields - 1)) == 0)
@@ -1525,7 +1524,7 @@ new_num_fields (size_t oldNumFields)
 
   /* Find the next power of two by setting all bits to the right of
      the leftmost 1 bit to 1, and then incrementing.  */
-  for (; oldNumFields & (oldNumFields + 1); n <<= 1)
+  for (n = 1; oldNumFields & (oldNumFields + 1); n <<= 1)
     oldNumFields |= oldNumFields >> n;
 
   return oldNumFields + 1;
@@ -1545,9 +1544,8 @@ find_key_or_nil (OOP dictionaryOOP,
   numFixedFields = OOP_FIXED_FIELDS (dictionaryOOP);
   numFields = NUM_WORDS (dictionary) - numFixedFields;
   index = scramble (OOP_INDEX (keyOOP));
-  count = numFields;
 
-  for (; count; count--)
+  for (count = numFields; count; count--)
     {
       index &= numFields - 1;
       associationOOP = dictionary->data[numFixedFields + index];
@@ -2025,7 +2023,7 @@ _gst_to_wide_cstring (OOP stringOOP)
   string = (gst_unicode_string) OOP_TO_OBJ (stringOOP);
   len = oop_num_fields (stringOOP);
   result = (wchar_t *) xmalloc (len + 1);
-  if (sizeof (wchar_t) == 4)
+  if (sizeof (wchar_t) == sizeof(string->chars[0]))
     memcpy (result, string->chars, len * sizeof (wchar_t));
   else
     for (p = result, i = 0; i < len; i++)
diff --git a/libgst/files.c b/libgst/files.c
index 531c7fe..ee14ecf 100644
--- a/libgst/files.c
+++ b/libgst/files.c
@@ -360,7 +360,7 @@ _gst_initialize (const char *kernel_dir,
   /* For the image file, it is okay to find none if we can/should rebuild
      the image file.  */
   if (image_file
-      && (flags & (GST_REBUILD_IMAGE | GST_MAYBE_REBUILD_IMAGE)) == 0
+      && !rebuild_image_flags
       && !_gst_file_is_readable (image_file))
     {
       if (flags & GST_IGNORE_BAD_IMAGE_PATH)
@@ -470,7 +470,7 @@ _gst_initialize (const char *kernel_dir,
       setvbuf (stdout, NULL, _IOLBF, 1024);
     }
 
-  if (rebuild_image_flags == 0)
+  if (!rebuild_image_flags)
     loadBinary = abortOnFailure = true;
   else
     {
diff --git a/libgst/save.c b/libgst/save.c
index be980a7..83e9692 100644
--- a/libgst/save.c
+++ b/libgst/save.c
@@ -419,7 +419,7 @@ save_object (int imageFd,
     abort ();
 
   numBytes = sizeof (OOP) * TO_INT (object->objSize);
-  if (numBytes < 262144)
+  if (numBytes < 256 * 1024)
     {
       saveObject = alloca (numBytes);
       fixup_object (oop, saveObject, object, numBytes);
-- 
2.9.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.