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