annotate src/array.c @ 5598:bccc91a65536

Fix .gdbinit and .dbxrc when using the new garbage collector. ChangeLog: 2011-11-21 Marcus Crestani <crestani@informatik.uni-tuebingen.de> * configure.ac: Fix creation of etc/dbxrc and src/.dbxrc; only try to create Makefile when Makefile.in is there. * configure: Regenerate. src/ChangeLog: 2011-11-21 Marcus Crestani <crestani@informatik.uni-tuebingen.de> * .gdbinit.in.in: There is no lrecord_type_lcrecord_list when using the new garbage collector; print $lrecord_type when Lisp Object type is unknown to pobj. etc/ChangeLog: 2011-11-21 Marcus Crestani <crestani@informatik.uni-tuebingen.de> * dbxrc.in: There is no lrecord_type_lcrecord_list when using the new garbage collector; print $lrecord_type when Lisp Object type is unknown to pobj.
author Marcus Crestani <crestani@informatik.uni-tuebingen.de>
date Mon, 21 Nov 2011 10:28:31 +0100
parents 308d34e9f07d
children f7abcda06b1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
1 /* Support for dynarrs and other types of dynamic arrays.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
2 Copyright (c) 1994, 1995 Free Software Foundation, Inc.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
3 Copyright (c) 1993, 1995 Sun Microsystems, Inc.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
4 Copyright (c) 1995, 1996, 2000, 2002, 2003, 2004, 2005, 2010 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5170
diff changeset
8 XEmacs is free software: you can redistribute it and/or modify it
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5170
diff changeset
10 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5170
diff changeset
11 option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5170
diff changeset
19 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 /* Synched up with: Not in FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* Written by Ben Wing, December 1993. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
25 #include <config.h>
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
26 #include "lisp.h"
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
27
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
28 #include "insdel.h"
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
29
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
30
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
31 /*****************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
32 /* "dynarr" a.k.a. dynamic array */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
33 /*****************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
34
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 /*
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
36 A "dynamic array" or "dynarr" is a contiguous array of fixed-size elements
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
37 where there is no upper limit (except available memory) on the number of
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
38 elements in the array. Because the elements are maintained contiguously,
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
39 space is used efficiently (no per-element pointers necessary) and random
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
40 access to a particular element is in constant time. At any one point, the
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
41 block of memory that holds the array has an upper limit; if this limit is
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
42 exceeded, the memory is realloc()ed into a new array that is twice as big.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
43 Assuming that the time to grow the array is on the order of the new size of
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
44 the array block, this scheme has a provably constant amortized time
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
45 \(i.e. average time over all additions).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 When you add elements or retrieve elements, pointers are used. Note that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 the element itself (of whatever size it is), and not the pointer to it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 is stored in the array; thus you do not have to allocate any heap memory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 on your own. Also, returned pointers are only guaranteed to be valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 until the next operation that changes the length of the array.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 This is a container object. Declare a dynamic array of a specific type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
56 typedef struct
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
57 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
58 Dynarr_declare (mytype);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
59 } mytype_dynarr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 Use the following functions/macros:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
63
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
64 ************* Dynarr creation *************
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
65
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 void *Dynarr_new(type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 [MACRO] Create a new dynamic-array object, with each element of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 specified type. The return value is cast to (type##_dynarr).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 This requires following the convention that types are declared in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 such a way that this type concatenation works. In particular, TYPE
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
71 must be a symbol, not an arbitrary C type. To make dynarrs of
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
72 complex types, a typedef must be declared, e.g.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
73
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
74 typedef unsigned char *unsigned_char_ptr;
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
75
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
76 and then you can say
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
77
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
78 unsigned_char_ptr_dynarr *dyn = Dynarr_new (unsigned_char_ptr);
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
79
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
80 void *Dynarr_new2(dynarr_type, type)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
81 [MACRO] Create a new dynamic-array object, with each element of the
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
82 specified type. The array itself is of type DYNARR_TYPE. This makes
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
83 it possible to create dynarrs over complex types without the need
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
84 to create typedefs, as described above. Use is as follows:
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
85
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
86 ucharptr_dynarr *dyn = Dynarr_new2 (ucharptr_dynarr *, unsigned char *);
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
87
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
88 Dynarr_free(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
89 Destroy a dynamic array and the memory allocated to it.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
90
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
91 ************* Dynarr access *************
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
92
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
93 type Dynarr_at(d, i)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
94 [MACRO] Return the element at the specified index. The index must be
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
95 between 0 and Dynarr_largest(d), inclusive. With error-checking
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
96 enabled, bounds checking on the index is in the form of asserts() --
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
97 an out-of-bounds index causes an abort. The element itself is
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
98 returned, not a pointer to it.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
99
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
100 type *Dynarr_atp(d, i)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
101 [MACRO] Return a pointer to the element at the specified index.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
102 Restrictions and bounds checking on the index is as for Dynarr_at.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
103 The pointer may not be valid after an element is added to or
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
104 (conceivably) removed from the array, because this may trigger a
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
105 realloc() performed on the underlying dynarr storage, which may
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
106 involve moving the entire underlying storage to a new location in
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
107 memory.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
108
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
109 type *Dynarr_begin(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
110 [MACRO] Return a pointer to the first element in the dynarr. See
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
111 Dynarr_atp() for warnings about when the pointer might become invalid.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
112
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
113 type *Dynarr_lastp(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
114 [MACRO] Return a pointer to the last element in the dynarr. See
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
115 Dynarr_atp() for warnings about when the pointer might become invalid.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
116
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
117 type *Dynarr_past_lastp(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
118 [MACRO] Return a pointer to the beginning of the element just past the
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
119 last one. WARNING: This may not point to valid memory; however, the
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
120 byte directly before will be pointer will be valid memory. This macro
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
121 might be useful for various reasons, e.g. as a stopping point in a loop
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
122 (although Dynarr_lastp() could be used just as well) or as a place to
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
123 start writing elements if Dynarr_length() < Dynarr_largest().
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
124
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
125 ************* Dynarr length/size retrieval and setting *************
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
126
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
127 int Dynarr_length(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
128 [MACRO] Return the number of elements currently in a dynamic array.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
129
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
130 int Dynarr_largest(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
131 [MACRO] Return the maximum value that Dynarr_length(d) would
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
132 ever have returned. This is used esp. in the redisplay code,
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
133 which reuses dynarrs for performance reasons.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
134
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
135 int Dynarr_max(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
136 [MACRO] Return the maximum number of elements that can fit in the
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
137 dynarr before it needs to be resized.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
138
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
139 Note that Dynarr_length(d) <= Dynarr_largest(d) <= Dynarr_max(d).
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
140
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
141 Bytecount Dynarr_sizeof(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
142 [MACRO] Return the total size of the elements currently in dynarr
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
143 D. This
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
144
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
145 Dynarr_set_lengthr(d, len)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
146 [MACRO] Set the length of D to LEN, which must be between 0 and
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
147 Dynarr_largest(d), inclusive. With error-checking enabled, an
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
148 assertion failure will result from trying to set the length
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
149 to less than zero or greater than Dynarr_largest(d). The
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
150 restriction to Dynarr_largest() is to ensure that
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
151
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
152 Dynarr_set_length(d, len)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
153 [MACRO] Set the length of D to LEN, resizing the dynarr as
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
154 necessary to make sure enough space is available. there are no
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
155 restrictions on LEN other than available memory and that it must
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
156 be at least 0. Note that
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
157
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
158 Dynarr_set_length_and_zero(d, len)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
159 [MACRO] Like Dynarr_set_length(d, len) but also, if increasing
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
160 the length, zero out the memory between the old and new lengths,
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
161 i.e. starting just past the previous last element and up through
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
162 the new last element.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
163
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
164 Dynarr_incrementr(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
165 [MACRO] Increments the length of D by 1. Equivalent to
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
166 Dynarr_set_lengthr(d, Dynarr_length(d) + 1).
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
167
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
168 Dynarr_increment(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
169 [MACRO] Increments the length of D by 1. Equivalent to
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
170 Dynarr_set_length(d, Dynarr_length(d) + 1).
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
171
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
172 Dynarr_reset(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
173 [MACRO] Reset the length of a dynamic array to 0.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
174
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
175 Dynarr_resize(d, maxval)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
176 Resize the internal dynarr storage to so that it can hold at least
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
177 MAXVAL elements. Resizing is done using a geometric series
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
178 (repeatedly multiply the old maximum by a constant, normally 1.5,
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
179 till a large enough size is reached), so this will be efficient
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
180 even if resizing larger by one element at a time. This is mostly
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
181 an internal function.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
182
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
183
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
184
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
185 ************* Adding/deleting elements to/from a dynarr *************
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 Dynarr_add(d, el)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 [MACRO] Add an element to the end of a dynamic array. EL is a pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 to the element; the element itself is stored in the array, however.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 No function call is performed unless the array needs to be resized.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 Dynarr_add_many(d, base, len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 [MACRO] Add LEN elements to the end of the dynamic array. The elements
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
194 should be contiguous in memory, starting at BASE. If BASE if NULL,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
195 just make space for the elements; don't actually add them.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
197 Dynarr_prepend_many(d, base, len)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
198 [MACRO] Prepend LEN elements to the beginning of the dynamic array.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 The elements should be contiguous in memory, starting at BASE.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
200 If BASE if NULL, just make space for the elements; don't actually
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
201 add them.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
203 Dynarr_insert_many(d, base, len, pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 Insert LEN elements to the dynamic array starting at position
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
205 POS. The elements should be contiguous in memory, starting at BASE.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
206 If BASE if NULL, just make space for the elements; don't actually
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
207 add them.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
208
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
209 type Dynarr_pop(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
210 [MACRO] Pop the last element off the dynarr and return it.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
211
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
212 Dynarr_delete(d, i)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
213 [MACRO] Delete an element from the dynamic array at position I.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
214
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
215 Dynarr_delete_many(d, pos, len)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
216 Delete LEN elements from the dynamic array starting at position
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
217 POS.
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
218
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
219 Dynarr_zero_many(d, pos, len)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
220 Zero out LEN elements in the dynarr D starting at position POS.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
221
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
222 Dynarr_delete_by_pointer(d, p)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
223 [MACRO] Delete an element from the dynamic array at pointer P,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
224 which must point within the block of memory that stores the data.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
225 P should be obtained using Dynarr_atp().
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
227 ************* Dynarr locking *************
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
229 Dynarr_lock(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
230 Lock the dynarr against further locking or writing. With error-checking
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
231 enabled, any attempts to write into a locked dynarr or re-lock an
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
232 already locked one will cause an assertion failure and abort.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
234 Dynarr_unlock(d)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
235 Unlock a locked dynarr, allowing writing into it.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
237 ************* Dynarr global variables *************
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 Dynarr_min_size
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
240 Minimum allowable size for a dynamic array when it is resized.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
244 static const struct memory_description const_Ascbyte_ptr_description_1[] = {
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
245 { XD_ASCII_STRING, 0 },
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
246 { XD_END }
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
247 };
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
248
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
249 const struct sized_memory_description const_Ascbyte_ptr_description = {
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
250 sizeof (const Ascbyte *),
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
251 const_Ascbyte_ptr_description_1
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
252 };
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
253
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
254 static const struct memory_description const_Ascbyte_ptr_dynarr_description_1[] = {
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
255 XD_DYNARR_DESC (const_Ascbyte_ptr_dynarr, &const_Ascbyte_ptr_description),
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
256 { XD_END }
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
257 };
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
258
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
259 const struct sized_memory_description const_Ascbyte_ptr_dynarr_description = {
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
260 sizeof (const_Ascbyte_ptr_dynarr),
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
261 const_Ascbyte_ptr_dynarr_description_1
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
262 };
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
263
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4844
diff changeset
264
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
265 static Elemcount Dynarr_min_size = 8;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 static void
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
268 Dynarr_realloc (Dynarr *dy, Elemcount new_size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 if (DUMPEDP (dy->base))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 {
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
272 void *new_base = malloc (new_size * Dynarr_elsize (dy));
3210
72b7d685c194 [xemacs-hg @ 2006-01-20 17:59:48 by crestani]
crestani
parents: 3092
diff changeset
273 memcpy (new_base, dy->base,
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
274 (Dynarr_max (dy) < new_size ? Dynarr_max (dy) : new_size) *
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
275 Dynarr_elsize (dy));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 dy->base = new_base;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 else
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
279 dy->base = xrealloc (dy->base, new_size * Dynarr_elsize (dy));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 void *
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
283 Dynarr_newf (Bytecount elsize)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 Dynarr *d = xnew_and_zero (Dynarr);
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
286 d->elsize_ = elsize;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 return d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
291 #ifdef NEW_GC
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 4117
diff changeset
292 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("dynarr", dynarr,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 4117
diff changeset
293 0, 0,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 4117
diff changeset
294 Dynarr);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
295
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
296 static void
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
297 Dynarr_lisp_realloc (Dynarr *dy, Elemcount new_size)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
298 {
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 4117
diff changeset
299 void *new_base =
5126
Ben Wing <ben@xemacs.org>
parents: 5125 5038
diff changeset
300 XPNTR (alloc_sized_lrecord_array (Dynarr_elsize (dy), new_size,
Ben Wing <ben@xemacs.org>
parents: 5125 5038
diff changeset
301 dy->lisp_imp));
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
302 if (dy->base)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
303 memcpy (new_base, dy->base,
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
304 (Dynarr_max (dy) < new_size ? Dynarr_max (dy) : new_size) *
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
305 Dynarr_elsize (dy));
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
306 dy->base = new_base;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
307 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
308
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
309 void *
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
310 Dynarr_lisp_newf (Bytecount elsize,
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
311 const struct lrecord_implementation *dynarr_imp,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
312 const struct lrecord_implementation *imp)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
313 {
5120
d1247f3cc363 latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
314 Dynarr *d = (Dynarr *) XPNTR (alloc_sized_lrecord (sizeof (Dynarr),
d1247f3cc363 latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
315 dynarr_imp));
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
316 d->elsize_ = elsize;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
317 d->lisp_imp = imp;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
318
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
319 return d;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
320 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
321 #endif /* not NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
322
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 void
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
324 Dynarr_resize (void *d, Elemcount size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 {
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
326 Elemcount newsize;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 double multiplier;
1318
b531bf8658e9 [xemacs-hg @ 2003-02-21 06:56:46 by ben]
ben
parents: 793
diff changeset
328 Dynarr *dy = (Dynarr *) Dynarr_verify (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
330 if (Dynarr_max (dy) <= 8)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 multiplier = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 multiplier = 1.5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
335 for (newsize = Dynarr_max (dy); newsize < size;)
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
336 newsize = max (Dynarr_min_size, (Elemcount) (multiplier * newsize));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 /* Don't do anything if the array is already big enough. */
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
339 if (newsize > Dynarr_max (dy))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
341 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
342 if (dy->lisp_imp)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
343 Dynarr_lisp_realloc (dy, newsize);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
344 else
3210
72b7d685c194 [xemacs-hg @ 2006-01-20 17:59:48 by crestani]
crestani
parents: 3092
diff changeset
345 Dynarr_realloc (dy, newsize);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
346 #else /* not NEW_GC */
3210
72b7d685c194 [xemacs-hg @ 2006-01-20 17:59:48 by crestani]
crestani
parents: 3092
diff changeset
347 Dynarr_realloc (dy, newsize);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
348 #endif /* not NEW_GC */
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
349 dy->max_ = newsize;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
353 /* Add a number of contiguous elements to the array starting at POS. */
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
354
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 void
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
356 Dynarr_insert_many (void *d, const void *base, Elemcount len, Elemcount pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 {
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
358 Dynarr *dy = Dynarr_verify_mod (d);
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
359 Elemcount old_len = Dynarr_length (dy);
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
360
4844
91b3d00e717f Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 4117
diff changeset
361 /* #### This could conceivably be wrong, if code wants to access stuff
91b3d00e717f Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 4117
diff changeset
362 between len and largest. */
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
363 dynarr_checking_assert (pos >= 0 && pos <= old_len);
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
364 dynarr_checking_assert (len >= 0);
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
365 Dynarr_increase_length (dy, old_len + len);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
367 if (pos != old_len)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 {
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
369 memmove ((Rawbyte *) dy->base + (pos + len)*Dynarr_elsize (dy),
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
370 (Rawbyte *) dy->base + pos*Dynarr_elsize (dy),
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
371 (old_len - pos)*Dynarr_elsize (dy));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 }
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
373 /* Some functions call us with a value of 0 to mean "reserve space but
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
374 don't write into it" */
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
375 if (base)
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
376 memcpy ((Rawbyte *) dy->base + pos*Dynarr_elsize (dy), base,
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
377 len*Dynarr_elsize (dy));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 void
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
381 Dynarr_delete_many (void *d, Elemcount pos, Elemcount len)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 {
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
383 Dynarr *dy = Dynarr_verify_mod (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
385 dynarr_checking_assert (pos >= 0 && len >= 0 &&
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
386 pos + len <= Dynarr_length (dy));
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
387
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
388 memmove ((Rawbyte *) dy->base + pos*Dynarr_elsize (dy),
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
389 (Rawbyte *) dy->base + (pos + len)*Dynarr_elsize (dy),
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
390 (Dynarr_length (dy) - pos - len)*Dynarr_elsize (dy));
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
391
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
392 Dynarr_set_length_1 (dy, Dynarr_length (dy) - len);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 Dynarr_free (void *d)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 Dynarr *dy = (Dynarr *) d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
400 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
401 if (dy->base && !DUMPEDP (dy->base))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
402 {
4117
229bd619740a [xemacs-hg @ 2007-08-15 11:06:02 by crestani]
crestani
parents: 3293
diff changeset
403 if (!dy->lisp_imp)
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
404 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
405 xfree (dy->base);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
406 dy->base = 0;
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
407 }
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
408 }
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
409 if (!DUMPEDP (dy))
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
410 {
4117
229bd619740a [xemacs-hg @ 2007-08-15 11:06:02 by crestani]
crestani
parents: 3293
diff changeset
411 if (!dy->lisp_imp)
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4967
diff changeset
412 xfree (dy);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
413 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
414 #else /* not NEW_GC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 if (dy->base && !DUMPEDP (dy->base))
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
416 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
417 xfree (dy->base);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
418 dy->base = 0;
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
419 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 if(!DUMPEDP (dy))
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4967
diff changeset
421 xfree (dy);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2500
diff changeset
422 #endif /* not NEW_GC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 #ifdef MEMORY_USAGE_STATS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
427 /* Return memory usage for dynarr D. The returned value is the total
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
428 amount of bytes actually being used for the dynarr, including all
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
429 overhead. The extra amount of space in the dynarr that is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 allocated beyond what was requested is returned in DYNARR_OVERHEAD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 in STATS. The extra amount of space that malloc() allocates beyond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 what was requested of it is returned in MALLOC_OVERHEAD in STATS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 See the comment above the definition of this structure. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
435 Bytecount
5157
1fae11d56ad2 redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents: 5126
diff changeset
436 Dynarr_memory_usage (void *d, struct usage_stats *stats)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
438 Bytecount total = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 Dynarr *dy = (Dynarr *) d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 /* We have to be a bit tricky here because not all of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 memory that malloc() will claim as "requested" was actually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 requested. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 if (dy->base)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 {
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
447 Bytecount malloc_used =
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
448 malloced_storage_size (dy->base, Dynarr_elsize (dy) * Dynarr_max (dy),
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
449 0);
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
450 /* #### This may or may not be correct. Some dynarrs would
4844
91b3d00e717f Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 4117
diff changeset
451 prefer that we use dy->len instead of dy->largest here. */
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
452 Bytecount was_requested = Dynarr_elsize (dy) * Dynarr_largest (dy);
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
453 Bytecount dynarr_overhead =
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
454 Dynarr_elsize (dy) * (Dynarr_max (dy) - Dynarr_largest (dy));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 total += malloc_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 stats->was_requested += was_requested;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 stats->dynarr_overhead += dynarr_overhead;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 /* And the remainder must be malloc overhead. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 stats->malloc_overhead +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 malloc_used - was_requested - dynarr_overhead;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 total += malloced_storage_size (d, sizeof (*dy), stats);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 return total;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 #endif /* MEMORY_USAGE_STATS */
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
470
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
471
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
472 /*****************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
473 /* stack-like allocation */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
474 /*****************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
475
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
476 /* Version of malloc() that will be extremely efficient when allocation
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
477 nearly always occurs in LIFO (stack) order.
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
478
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
479 #### Perhaps shouldn't be in this file, but where else? */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
480
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
481 typedef struct
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
482 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
483 Dynarr_declare (char_dynarr *);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
484 } char_dynarr_dynarr;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
485
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
486 char_dynarr_dynarr *stack_like_free_list;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
487 char_dynarr_dynarr *stack_like_in_use_list;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
488
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
489 void *
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
490 stack_like_malloc (Bytecount size)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
491 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
492 char_dynarr *this_one;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
493 if (!stack_like_free_list)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
494 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
495 stack_like_free_list = Dynarr_new2 (char_dynarr_dynarr,
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
496 char_dynarr *);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
497 stack_like_in_use_list = Dynarr_new2 (char_dynarr_dynarr,
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
498 char_dynarr *);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
499 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
500
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
501 if (Dynarr_length (stack_like_free_list) > 0)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
502 this_one = Dynarr_pop (stack_like_free_list);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
503 else
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
504 this_one = Dynarr_new (char);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
505 Dynarr_add (stack_like_in_use_list, this_one);
4844
91b3d00e717f Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 4117
diff changeset
506 Dynarr_reset (this_one);
91b3d00e717f Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 4117
diff changeset
507 Dynarr_add_many (this_one, 0, size);
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
508 return Dynarr_begin (this_one);
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
509 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
510
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
511 void
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
512 stack_like_free (void *val)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
513 {
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5023
diff changeset
514 Elemcount len = Dynarr_length (stack_like_in_use_list);
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
515 assert (len > 0);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
516 /* The vast majority of times, we will be called in a last-in first-out
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
517 order, and the item at the end of the list will be the one we're
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
518 looking for, so just check for this first and avoid any function
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
519 calls. */
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
520 if (Dynarr_begin (Dynarr_at (stack_like_in_use_list, len - 1)) == val)
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
521 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
522 char_dynarr *this_one = Dynarr_pop (stack_like_in_use_list);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
523 Dynarr_add (stack_like_free_list, this_one);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
524 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
525 else
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
526 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
527 /* Find the item and delete it. */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
528 int i;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
529 assert (len >= 2);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
530 for (i = len - 2; i >= 0; i--)
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
531 if (Dynarr_begin (Dynarr_at (stack_like_in_use_list, i)) ==
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
532 val)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
533 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
534 char_dynarr *this_one = Dynarr_at (stack_like_in_use_list, i);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
535 Dynarr_add (stack_like_free_list, this_one);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
536 Dynarr_delete (stack_like_in_use_list, i);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
537 return;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
538 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
539
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
540 ABORT ();
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
541 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 1726
diff changeset
542 }
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
543
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
544
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
545 /*****************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
546 /* Generalized gap array */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
547 /*****************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
548
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
549 /* A "gap array" is an array that has a "gap" somewhere in the middle of it,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
550 so that insertions and deletions near the gap -- or in general, highly
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
551 localized insertions and deletions -- are very fast. Inserting or
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
552 deleting works by first moving the gap to the insertion or deletion
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
553 position and then shortening or lengthening the gap as necessary. The
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
554 idea comes from the gap used in storing text in a buffer.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
555
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
556 The gap array interface differs in a number of ways from dynarrs (####
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
557 and should be changed so that it works the same as dynarrs):
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
558
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
559 (1) There aren't separate type-specific gap array types. As a result,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
560 operations like gap_array_at() require that the type be specified as
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
561 one of the arguments. It is often more convenient to use a macro
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
562 wrapper around this operation.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
563
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
564 (2) The gap array type is itself a stretchy array rather than using a
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
565 separate block of memory to store the array. This means that certain
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
566 operations (especially insertions) may relocate the the gap array,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
567 and as a result return a pointer to the (possibly) moved gap array,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
568 which must be stored back into the location where the gap array
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
569 pointer resides. This also means that the caller must worry about
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
570 cloning the gap array in the case where it has been dumped, or you
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
571 will get an ABORT() inside of xrealloc().
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
572
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
573 (3) Fewer operations are available than for dynarrs, and may have
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
574 different names and/or different calling conventions.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
575
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
576 (4) The mechanism for creating "Lisp-object gap arrays" isn't completely
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
577 developed. Currently it's only possible to create a gap-array Lisp
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
578 object that wraps Lisp_Object pointers (not Lisp object structures
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
579 directly), and only under NEW_GC.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
580
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
581 (5) Gap arrays have a concept of a "gap array marker" that properly
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
582 tracks insertions and deletions; no such thing exists in dynarrs.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
583 It exists in gap arrays because it's necessary for their use in
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
584 implementing extent lists.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
585 */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
586
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
587 extern const struct sized_memory_description gap_array_marker_description;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
588
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
589 static const struct memory_description gap_array_marker_description_1[] = {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
590 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
591 { XD_LISP_OBJECT, offsetof (Gap_Array_Marker, next) },
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
592 #else /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
593 { XD_BLOCK_PTR, offsetof (Gap_Array_Marker, next), 1,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
594 { &gap_array_marker_description } },
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
595 #endif /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
596 { XD_END }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
597 };
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
598
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
599 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
600 DEFINE_NODUMP_INTERNAL_LISP_OBJECT ("gap-array-marker", gap_array_marker,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
601 0, gap_array_marker_description_1,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
602 struct gap_array_marker);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
603 #else /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
604 const struct sized_memory_description gap_array_marker_description = {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
605 sizeof (Gap_Array_Marker),
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
606 gap_array_marker_description_1
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
607 };
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
608 #endif /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
609
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
610 static const struct memory_description lispobj_gap_array_description_1[] = {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
611 XD_GAP_ARRAY_DESC (&lisp_object_description),
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
612 { XD_END }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
613 };
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
614
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
615 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
616
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
617 static Bytecount
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
618 size_gap_array (Lisp_Object obj)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
619 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
620 Gap_Array *ga = XGAP_ARRAY (obj);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
621 return gap_array_byte_size (ga);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
622 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
623
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
624 DEFINE_DUMPABLE_SIZABLE_INTERNAL_LISP_OBJECT ("gap-array", gap_array,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
625 0,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
626 lispobj_gap_array_description_1,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
627 size_gap_array,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
628 struct gap_array);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
629 #else /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
630 const struct sized_memory_description lispobj_gap_array_description = {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
631 0, lispobj_gap_array_description_1
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
632 };
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
633 #endif /* (not) NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
634
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
635 #ifndef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
636 static Gap_Array_Marker *gap_array_marker_freelist;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
637 #endif /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
638
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
639 /* This generalizes the "array with a gap" model used to store buffer
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
640 characters. This is based on the stuff in insdel.c and should
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
641 probably be merged with it. This is not extent-specific and should
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
642 perhaps be moved into a separate file. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
643
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
644 /* ------------------------------- */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
645 /* internal functions */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
646 /* ------------------------------- */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
647
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
648 /* Adjust the gap array markers in the range (FROM, TO]. Parallel to
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
649 adjust_markers() in insdel.c. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
650
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
651 static void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
652 gap_array_adjust_markers (Gap_Array *ga, Memxpos from,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
653 Memxpos to, Elemcount amount)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
654 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
655 Gap_Array_Marker *m;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
656
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
657 for (m = ga->markers; m; m = m->next)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
658 m->pos = do_marker_adjustment (m->pos, from, to, amount);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
659 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
660
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
661 static void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
662 gap_array_recompute_derived_values (Gap_Array *ga)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
663 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
664 ga->offset_past_gap = ga->elsize * (ga->gap + ga->gapsize);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
665 ga->els_past_gap = ga->numels - ga->gap;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
666 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
667
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
668 /* Move the gap to array position POS. Parallel to move_gap() in
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
669 insdel.c but somewhat simplified. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
670
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
671 static void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
672 gap_array_move_gap (Gap_Array *ga, Elemcount pos)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
673 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
674 Elemcount gap = ga->gap;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
675 Elemcount gapsize = ga->gapsize;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
676
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
677 if (pos < gap)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
678 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
679 memmove (GAP_ARRAY_MEMEL_ADDR (ga, pos + gapsize),
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
680 GAP_ARRAY_MEMEL_ADDR (ga, pos),
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
681 (gap - pos)*ga->elsize);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
682 gap_array_adjust_markers (ga, (Memxpos) pos, (Memxpos) gap,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
683 gapsize);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
684 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
685 else if (pos > gap)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
686 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
687 memmove (GAP_ARRAY_MEMEL_ADDR (ga, gap),
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
688 GAP_ARRAY_MEMEL_ADDR (ga, gap + gapsize),
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
689 (pos - gap)*ga->elsize);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
690 gap_array_adjust_markers (ga, (Memxpos) (gap + gapsize),
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
691 (Memxpos) (pos + gapsize), - gapsize);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
692 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
693 ga->gap = pos;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
694
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
695 gap_array_recompute_derived_values (ga);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
696 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
697
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
698 /* Make the gap INCREMENT characters longer. Parallel to make_gap() in
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
699 insdel.c. The gap array may be moved, so assign the return value back
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
700 to the array pointer. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
701
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
702 static Gap_Array *
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
703 gap_array_make_gap (Gap_Array *ga, Elemcount increment)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
704 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
705 Elemcount real_gap_loc;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
706 Elemcount old_gap_size;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
707
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
708 /* If we have to get more space, get enough to last a while. We use
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
709 a geometric progression that saves on realloc space. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
710 increment += 100 + ga->numels / 8;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
711
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
712 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
713 if (ga->is_lisp)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
714 ga = (Gap_Array *) mc_realloc (ga,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
715 offsetof (Gap_Array, array) +
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
716 (ga->numels + ga->gapsize + increment) *
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
717 ga->elsize);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
718 else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
719 #endif /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
720 ga = (Gap_Array *) xrealloc (ga,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
721 offsetof (Gap_Array, array) +
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
722 (ga->numels + ga->gapsize + increment) *
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
723 ga->elsize);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
724 if (ga == 0)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
725 memory_full ();
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
726
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
727 real_gap_loc = ga->gap;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
728 old_gap_size = ga->gapsize;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
729
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
730 /* Call the newly allocated space a gap at the end of the whole space. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
731 ga->gap = ga->numels + ga->gapsize;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
732 ga->gapsize = increment;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
733
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
734 /* Move the new gap down to be consecutive with the end of the old one.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
735 This adjusts the markers properly too. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
736 gap_array_move_gap (ga, real_gap_loc + old_gap_size);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
737
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
738 /* Now combine the two into one large gap. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
739 ga->gapsize += old_gap_size;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
740 ga->gap = real_gap_loc;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
741
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
742 gap_array_recompute_derived_values (ga);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
743
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
744 return ga;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
745 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
746
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
747 /* ------------------------------- */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
748 /* external functions */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
749 /* ------------------------------- */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
750
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
751 Bytecount
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
752 gap_array_byte_size (Gap_Array *ga)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
753 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
754 return offsetof (Gap_Array, array) + (ga->numels + ga->gapsize) * ga->elsize;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
755 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
756
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
757 /* Insert NUMELS elements (pointed to by ELPTR) into the specified
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
758 gap array at POS. The gap array may be moved, so assign the
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
759 return value back to the array pointer. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
760
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
761 Gap_Array *
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
762 gap_array_insert_els (Gap_Array *ga, Elemcount pos, void *elptr,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
763 Elemcount numels)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
764 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
765 assert (pos >= 0 && pos <= ga->numels);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
766 if (ga->gapsize < numels)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
767 ga = gap_array_make_gap (ga, numels - ga->gapsize);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
768 if (pos != ga->gap)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
769 gap_array_move_gap (ga, pos);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
770
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
771 memcpy (GAP_ARRAY_MEMEL_ADDR (ga, ga->gap), (char *) elptr,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
772 numels*ga->elsize);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
773 ga->gapsize -= numels;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
774 ga->gap += numels;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
775 ga->numels += numels;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
776 gap_array_recompute_derived_values (ga);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
777 /* This is the equivalent of insert-before-markers.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
778
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
779 #### Should only happen if marker is "moves forward at insert" type.
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
780 */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
781
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
782 gap_array_adjust_markers (ga, pos - 1, pos, numels);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
783 return ga;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
784 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
785
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
786 /* Delete NUMELS elements from the specified gap array, starting at FROM. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
787
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
788 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
789 gap_array_delete_els (Gap_Array *ga, Elemcount from, Elemcount numdel)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
790 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
791 Elemcount to = from + numdel;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
792 Elemcount gapsize = ga->gapsize;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
793
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
794 assert (from >= 0);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
795 assert (numdel >= 0);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
796 assert (to <= ga->numels);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
797
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
798 /* Make sure the gap is somewhere in or next to what we are deleting. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
799 if (to < ga->gap)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
800 gap_array_move_gap (ga, to);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
801 if (from > ga->gap)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
802 gap_array_move_gap (ga, from);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
803
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
804 /* Relocate all markers pointing into the new, larger gap
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
805 to point at the end of the text before the gap. */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
806 gap_array_adjust_markers (ga, to + gapsize, to + gapsize,
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
807 - numdel - gapsize);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
808
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
809 ga->gapsize += numdel;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
810 ga->numels -= numdel;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
811 ga->gap = from;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
812 gap_array_recompute_derived_values (ga);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
813 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
814
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
815 Gap_Array_Marker *
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
816 gap_array_make_marker (Gap_Array *ga, Elemcount pos)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
817 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
818 Gap_Array_Marker *m;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
819
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
820 assert (pos >= 0 && pos <= ga->numels);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
821 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
822 m = XGAP_ARRAY_MARKER (ALLOC_NORMAL_LISP_OBJECT (gap_array_marker));
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
823 #else /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
824 if (gap_array_marker_freelist)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
825 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
826 m = gap_array_marker_freelist;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
827 gap_array_marker_freelist = gap_array_marker_freelist->next;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
828 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
829 else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
830 m = xnew (Gap_Array_Marker);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
831 #endif /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
832
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
833 m->pos = GAP_ARRAY_ARRAY_TO_MEMORY_POS (ga, pos);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
834 m->next = ga->markers;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
835 ga->markers = m;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
836 return m;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
837 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
838
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
839 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
840 gap_array_delete_marker (Gap_Array *ga, Gap_Array_Marker *m)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
841 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
842 Gap_Array_Marker *p, *prev;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
843
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
844 for (prev = 0, p = ga->markers; p && p != m; prev = p, p = p->next)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
845 ;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
846 assert (p);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
847 if (prev)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
848 prev->next = p->next;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
849 else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
850 ga->markers = p->next;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
851 #ifndef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
852 m->next = gap_array_marker_freelist;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
853 m->pos = 0xDEADBEEF; /* -559038737 base 10 */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
854 gap_array_marker_freelist = m;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
855 #endif /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
856 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
857
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
858 #ifndef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
859 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
860 gap_array_delete_all_markers (Gap_Array *ga)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
861 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
862 Gap_Array_Marker *p, *next;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
863
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
864 for (p = ga->markers; p; p = next)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
865 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
866 next = p->next;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
867 p->next = gap_array_marker_freelist;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
868 p->pos = 0xDEADBEEF; /* -559038737 as an int */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
869 gap_array_marker_freelist = p;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
870 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
871 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
872 #endif /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
873
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
874 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
875 gap_array_move_marker (Gap_Array *ga, Gap_Array_Marker *m, Elemcount pos)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
876 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
877 assert (pos >= 0 && pos <= ga->numels);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
878 m->pos = GAP_ARRAY_ARRAY_TO_MEMORY_POS (ga, pos);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
879 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
880
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
881 Gap_Array *
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
882 make_gap_array (Elemcount elsize, int USED_IF_NEW_GC (do_lisp))
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
883 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
884 Gap_Array *ga;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
885 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
886 /* #### I don't quite understand why it's necessary to make all these
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
887 internal objects into Lisp objects under NEW_GC. It's a pain in the
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
888 ass to code around this. I'm proceeding on the assumption that it's
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
889 not really necessary to do it after all, and so we only make a Lisp-
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
890 object gap array when the object being held is a Lisp_Object, i.e. a
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
891 pointer to a Lisp object. In the case where instead we hold a `struct
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
892 range_table_entry', just blow it off. Otherwise we either need to do
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
893 a bunch of painful and/or boring rewriting. --ben */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
894 if (do_lisp)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
895 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
896 ga = XGAP_ARRAY (ALLOC_SIZED_LISP_OBJECT (sizeof (Gap_Array),
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
897 gap_array));
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
898 ga->is_lisp = 1;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
899 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
900 else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
901 #endif /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
902 ga = xnew_and_zero (Gap_Array);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
903 ga->elsize = elsize;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
904 return ga;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
905 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
906
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
907 Gap_Array *
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
908 gap_array_clone (Gap_Array *ga)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
909 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
910 Bytecount size = gap_array_byte_size (ga);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
911 Gap_Array *ga2;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
912 Gap_Array_Marker *m;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
913
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
914 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
915 if (ga->is_lisp)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
916 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
917 ga2 = XGAP_ARRAY (ALLOC_SIZED_LISP_OBJECT (size, gap_array));
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
918 copy_lisp_object (wrap_gap_array (ga2), wrap_gap_array (ga));
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
919 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
920 else
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
921 #endif
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
922 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
923 ga2 = (Gap_Array *) xmalloc (size);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
924 memcpy (ga2, ga, size);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
925 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
926 ga2->markers = NULL;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
927 for (m = ga->markers; m; m = m->next)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
928 gap_array_make_marker (ga2, m->pos);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
929 return ga2;
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
930 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
931
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
932 #ifndef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
933 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
934 free_gap_array (Gap_Array *ga)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
935 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
936 gap_array_delete_all_markers (ga);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
937 xfree (ga);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
938 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
939 #endif /* not NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
940
5170
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
941 #ifdef MEMORY_USAGE_STATS
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
942
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
943 /* Return memory usage for gap array GA. The returned value is the total
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
944 amount of bytes actually being used for the gap array, including all
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
945 overhead. The extra amount of space in the gap array that is used
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
946 for the gap is counted in GAP_OVERHEAD, not in WAS_REQUESTED.
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
947 If NEW_GC, space for gap-array markers is returned through MARKER_ANCILLARY;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
948 otherwise it's added into the gap array usage. */
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
949
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
950 Bytecount
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
951 gap_array_memory_usage (Gap_Array *ga, struct usage_stats *stats,
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
952 Bytecount *marker_ancillary)
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
953 {
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
954 Bytecount total = 0;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
955
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
956 /* We have to be a bit tricky here because not all of the
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
957 memory that malloc() will claim as "requested" was actually
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
958 requested -- some of it makes up the gap. */
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
959
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
960 Bytecount size = gap_array_byte_size (ga);
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
961 Bytecount gap_size = ga->gapsize * ga->elsize;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
962 Bytecount malloc_used = malloced_storage_size (ga, size, 0);
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
963 total += malloc_used;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
964 stats->was_requested += size - gap_size;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
965 stats->gap_overhead += gap_size;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
966 stats->malloc_overhead += malloc_used - size;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
967
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
968 #ifdef NEW_GC
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
969 {
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
970 Bytecount marker_usage = 0;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
971 Gap_Array_Marker *p;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
972
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
973 for (p = ga->markers; p; p = p->next)
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
974 marker_usage += lisp_object_memory_usage (wrap_gap_array_marker (p));
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
975 if (marker_ancillary)
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
976 *marker_ancillary = marker_usage;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
977 }
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
978 #else
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
979 {
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
980 Gap_Array_Marker *p;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
981
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
982 for (p = ga->markers; p; p = p->next)
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
983 total += malloced_storage_size (p, sizeof (p), stats);
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
984 if (marker_ancillary)
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
985 *marker_ancillary = 0;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
986 }
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
987 #endif /* (not) NEW_GC */
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
988
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
989 return total;
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
990 }
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
991
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
992 #endif /* MEMORY_USAGE_STATS */
5ddbab03b0e6 various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents: 5169
diff changeset
993
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
994
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
995 /*****************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
996 /* Initialization */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
997 /*****************************************************************************/
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
998
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
999 void
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
1000 syms_of_array (void)
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
1001 {
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
1002 #ifdef NEW_GC
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
1003 INIT_LISP_OBJECT (gap_array_marker);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
1004 INIT_LISP_OBJECT (gap_array);
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
1005 #endif /* NEW_GC */
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
1006 }
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5157
diff changeset
1007