slavapestov/factor — pull request #262 by jckarter (2011-10-15 06:39:41+00:00)
Title: Non-copying stream-read operations

* Change the input stream protocol to require `stream-read-unsafe` and `stream-read-partial-unsafe` methods, which take a `c-ptr` for byte streams or an already-allocated `string` for character streams. Implement `stream-read` and `stream-read-partial` over these generics, and also provide new `(stream-)read-into` functions that fill a user-provided binary sequence or string.
* `contents` was pathologically slow on `decoder` streams, which in turn made `decode` on strings pathologically slow. Make `stream-contents` generic so streams can provide a better implementation than the default. `decode` and `encode` are further riced by preallocating their result buffers based on new `guess-encoded-length` and `guess-decoded-length` hints encoders may provide. Fixes #248.
* Add `stream-seekable?` and `stream-length` methods for seekable streams. `stream-contents` can use `stream-length` when available to pre-allocate a buffer and read into it using `stream-read-unsafe`.
* Provide lame but reliable default implementations of the stream protocol in terms of `stream-read1` and `stream-write1`, so it's easy to get new stream types going quickly, and we don't have to deal with different stream classes providing different strange cross-sections of the API.
* Make `reallot_array` in the VM cut out early if the requested new size equals the current size. Previously `resize` would reallot arrays, strings, and byte-arrays even if the size was the same.