aboutsummaryrefslogtreecommitdiff
path: root/ltable.h
diff options
context:
space:
mode:
Diffstat (limited to 'ltable.h')
-rw-r--r--ltable.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/ltable.h b/ltable.h
index 8b0340b5..8688264c 100644
--- a/ltable.h
+++ b/ltable.h
@@ -87,20 +87,32 @@
87 87
88 88
89/* 89/*
90** The array part of a table is represented by an array of cells. 90** The array part of a table is represented by an array of *cells*.
91** Each cell is composed of NM tags followed by NM values, so that 91** Each cell is composed of NM tags followed by NM values, so that
92** no space is wasted in padding. 92** no space is wasted in padding.
93*/ 93*/
94#define NM cast_uint(sizeof(Value)) 94#define NM cast_uint(sizeof(Value))
95 95
96
97/*
98** A few operations on arrays can be performed "in bulk", treating all
99** tags of a cell as a simple (or a few) word(s). The next constant is
100** the number of words to cover the tags of a cell. (In conventional
101** architectures that will be 1 or 2.)
102*/
103#define BKSZ cast_int((NM - 1) / sizeof(lua_Unsigned) + 1)
104
96struct ArrayCell { 105struct ArrayCell {
97 lu_byte tag[NM]; 106 union {
107 lua_Unsigned bulk[BKSZ]; /* for "bulk" operations */
108 lu_byte tag[NM];
109 } u;
98 Value value[NM]; 110 Value value[NM];
99}; 111};
100 112
101 113
102/* Computes the address of the tag for the abstract index 'k' */ 114/* Computes the address of the tag for the abstract index 'k' */
103#define getArrTag(t,k) (&(t)->array[(k)/NM].tag[(k)%NM]) 115#define getArrTag(t,k) (&(t)->array[(k)/NM].u.tag[(k)%NM])
104 116
105/* Computes the address of the value for the abstract index 'k' */ 117/* Computes the address of the value for the abstract index 'k' */
106#define getArrVal(t,k) (&(t)->array[(k)/NM].value[(k)%NM]) 118#define getArrVal(t,k) (&(t)->array[(k)/NM].value[(k)%NM])