Although the tidying up of resources.c is not complete yet, I decided to implement COW strings anyway.
This implementation handles the following: Copied strings and substrings are COWed instead of copied (i.e. new string header only); this applies to normal and constant strings. Functions that alter strings in-place make a new copy first if required (actually, in some circumstances copies are made when they could be avoided; this will be fixed shortly) The GC process will detect when a previously shared buffer is no longer shared, and clear the COW flag The COWing of substrings requires a major interface change: *** All references to the data in a STRING must use the new strstart pointer instead of bufstart *** This patch makes that change to current CVS code; all work-in-progress will need to be amended accordingly. Note that the JIT code has been broken in the process; I have left that for somebody who understands it. The 'string_tail' data added to the end of (non-constant) strings has been defined as a struct in case any other uses are found for it. The meaning of BUFFER_constant_FLAG has been changed slightly; it now means that the buffer resides in the (uncompacted) constant string pool; the header may be for a true constant or for a copy/substring of one. In the latter case, the BUFFER_COW_FLAG will also be set. A new function 'string_append' has also been added, for two-argument concatenation. I believe that this operation will be common enough to warrant an optimised function for it. Tests have been added to string.t for specific problems encountered during this exercise that did not cause any of the existing tests to fail. Additional tests for the functionality of the COW system will be added shortly. Performance seems to be somewhat improved for string-intensive programs (eg life). Because of the split pools, non-string buffers do not suffer any additional overhead, so performance of non-string-intensive programs should be unaffected. Feedback welcome. -- Peter Gibbs EmKel Systems
phase3.patch
Description: Binary data