Add scm_make_foreign_object_0; optimize scm_make_foreign_object_n.
authorAndy Wingo <wingo@pobox.com>
Mon, 28 Apr 2014 08:55:26 +0000 (10:55 +0200)
committerAndy Wingo <wingo@pobox.com>
Mon, 28 Apr 2014 08:59:16 +0000 (10:59 +0200)
* libguile/foreign-object.c (scm_make_foreign_object_0): New function.
  (scm_make_foreign_object_n): Pre-fetch layout_chars.

* libguile/foreign-object.h: Add scm_make_foreign_object_0.

libguile/foreign-object.c
libguile/foreign-object.h

index 78b017a..ef4d7dd 100644 (file)
@@ -63,6 +63,12 @@ scm_assert_foreign_object_type (SCM type, SCM val)
                scm_list_2 (scm_class_name (type), val), scm_list_1 (val));
 }
 
+SCM
+scm_make_foreign_object_0 (SCM type)
+{
+  return scm_make_foreign_object_n (type, 0, NULL);
+}
+
 SCM
 scm_make_foreign_object_1 (SCM type, scm_t_bits val0)
 {
@@ -93,6 +99,7 @@ scm_make_foreign_object_n (SCM type, size_t n, scm_t_bits vals[])
   SCM obj;
   SCM layout;
   size_t i;
+  const char *layout_chars;
 
   SCM_VALIDATE_VTABLE (SCM_ARG1, type);
 
@@ -101,8 +108,9 @@ scm_make_foreign_object_n (SCM type, size_t n, scm_t_bits vals[])
   if (scm_i_symbol_length (layout) / 2 < n)
     scm_out_of_range (FUNC_NAME, scm_from_size_t (n));
 
+  layout_chars = scm_i_symbol_chars (layout);
   for (i = 0; i < n; i++)
-    if (scm_i_symbol_ref (layout, i * 2) != 'u')
+    if (layout_chars[i * 2] != 'u')
       scm_wrong_type_arg_msg (FUNC_NAME, 0, layout, "'u' field");
 
   obj = scm_c_make_structv (type, 0, 0, NULL);
index fadb3b5..3b7784e 100644 (file)
@@ -32,6 +32,7 @@ SCM_API SCM scm_make_foreign_object_type (SCM name, SCM slot_names,
 
 SCM_API void scm_assert_foreign_object_type (SCM type, SCM val);
 
+SCM_API SCM scm_make_foreign_object_0 (SCM type);
 SCM_API SCM scm_make_foreign_object_1 (SCM type, scm_t_bits val0);
 SCM_API SCM scm_make_foreign_object_2 (SCM type, scm_t_bits val0,
                                         scm_t_bits val1);