mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Optimize struct initialization and accessors for the common case.
* libguile/struct.c (set_vtable_layout_flags): New function. (scm_i_struct_inherit_vtable_magic): Use it. (scm_struct_init): Optimize the case where HANDLE's vtable has the `SCM_VTABLE_FLAG_SIMPLE' flag. (scm_struct_ref): Likewise. (scm_struct_ref): Likewise, when `SCM_VTABLE_FLAG_SIMPLE_RW' is also set. * libguile/struct.h (SCM_VTABLE_BASE_LAYOUT): Update comment for the next-to-last hidden field. (scm_vtable_index_reserved_6): Rename to... (scm_vtable_index_size): ... this. (SCM_VTABLE_FLAG_RESERVED_0): Rename to... (SCM_VTABLE_FLAG_SIMPLE): ... this. (SCM_VTABLE_FLAG_RESERVED_1): Rename to... (SCM_VTABLE_FLAG_SIMPLE_RW): ... this. * test-suite/tests/structs.test ("low-level struct procedures")["struct-ref", "struct-set!", "struct-ref out-of-range", "struct-set! out-of-range"]: New tests.
This commit is contained in:
parent
0e64cbea3d
commit
aa42c03669
3 changed files with 266 additions and 154 deletions
|
@ -3,7 +3,7 @@
|
|||
#ifndef SCM_STRUCT_H
|
||||
#define SCM_STRUCT_H
|
||||
|
||||
/* Copyright (C) 1995,1997,1999,2000,2001, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1995,1997,1999,2000,2001, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
|
@ -41,12 +41,12 @@
|
|||
/* All vtables have the following fields. */
|
||||
#define SCM_VTABLE_BASE_LAYOUT \
|
||||
"pr" /* layout */ \
|
||||
"uh" /* flags */ \
|
||||
"uh" /* flags */ \
|
||||
"sr" /* self */ \
|
||||
"uh" /* finalizer */ \
|
||||
"pw" /* printer */ \
|
||||
"ph" /* name (hidden from make-struct for back-compat reasons) */ \
|
||||
"uh" /* reserved */ \
|
||||
"uh" /* size */ \
|
||||
"uh" /* reserved */
|
||||
|
||||
#define scm_vtable_index_layout 0 /* A symbol describing the physical arrangement of this type. */
|
||||
|
@ -55,7 +55,7 @@
|
|||
#define scm_vtable_index_instance_finalize 3 /* Finalizer for instances of this struct type. */
|
||||
#define scm_vtable_index_instance_printer 4 /* A printer for this struct type. */
|
||||
#define scm_vtable_index_name 5 /* Name of this vtable. */
|
||||
#define scm_vtable_index_reserved_6 6
|
||||
#define scm_vtable_index_size 6 /* Number of fields, for simple structs. */
|
||||
#define scm_vtable_index_reserved_7 7
|
||||
#define scm_vtable_offset_user 8 /* Where do user fields start in the vtable? */
|
||||
|
||||
|
@ -79,8 +79,8 @@
|
|||
#define SCM_VTABLE_FLAG_APPLICABLE (1L << 2) /* instances of this vtable are applicable? */
|
||||
#define SCM_VTABLE_FLAG_SETTER_VTABLE (1L << 3) /* instances of this vtable are applicable-with-setter vtables? */
|
||||
#define SCM_VTABLE_FLAG_SETTER (1L << 4) /* instances of this vtable are applicable-with-setters? */
|
||||
#define SCM_VTABLE_FLAG_RESERVED_0 (1L << 5)
|
||||
#define SCM_VTABLE_FLAG_RESERVED_1 (1L << 6)
|
||||
#define SCM_VTABLE_FLAG_SIMPLE (1L << 5) /* instances of this vtable have only "pr" fields */
|
||||
#define SCM_VTABLE_FLAG_SIMPLE_RW (1L << 6) /* instances of this vtable have only "pw" fields */
|
||||
#define SCM_VTABLE_FLAG_SMOB_0 (1L << 7)
|
||||
#define SCM_VTABLE_FLAG_GOOPS_0 (1L << 8)
|
||||
#define SCM_VTABLE_FLAG_GOOPS_1 (1L << 9)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue