summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2014-04-28 10:55:26 +0200
committerAndy Wingo <wingo@pobox.com>2014-04-28 10:59:16 +0200
commitea4c2460e048a575fc9db0715a7f41881f2b39a5 (patch)
tree5b55ae9dc6f2cb9f09c429705afc9962581f2528
parenta7ee7f7cbf1042cf9e4b4c4f3b28b6759ccbce4f (diff)
Add scm_make_foreign_object_0; optimize scm_make_foreign_object_n.
* 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.
-rw-r--r--libguile/foreign-object.c10
-rw-r--r--libguile/foreign-object.h1
2 files changed, 10 insertions, 1 deletions
diff --git a/libguile/foreign-object.c b/libguile/foreign-object.c
index 78b017aa5..ef4d7dd4f 100644
--- a/libguile/foreign-object.c
+++ b/libguile/foreign-object.c
@@ -64,6 +64,12 @@ scm_assert_foreign_object_type (SCM type, SCM 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)
{
return scm_make_foreign_object_n (type, 1, &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);
diff --git a/libguile/foreign-object.h b/libguile/foreign-object.h
index fadb3b554..3b7784eb6 100644
--- a/libguile/foreign-object.h
+++ b/libguile/foreign-object.h
@@ -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);