--- /dev/null
- <byte-array> 0 byte-vector boa ; inline\r
+ ! Copyright (C) 2008 Slava Pestov.\r
+ ! See http://factorcode.org/license.txt for BSD license.\r
+ USING: arrays kernel kernel.private math sequences\r
+ sequences.private growable byte-arrays accessors parser\r
+ prettyprint.custom ;\r
+ IN: byte-vectors\r
+ \r
+ TUPLE: byte-vector\r
+ { underlying byte-array }\r
+ { length array-capacity } ;\r
+ \r
+ : <byte-vector> ( n -- byte-vector )\r
- drop [ <byte-array> ] [ >fixnum ] bi byte-vector boa ;\r
++ (byte-array) 0 byte-vector boa ; inline\r
+ \r
+ : >byte-vector ( seq -- byte-vector )\r
+ T{ byte-vector f B{ } 0 } clone-like ;\r
+ \r
+ M: byte-vector like\r
+ drop dup byte-vector? [\r
+ dup byte-array?\r
+ [ dup length byte-vector boa ] [ >byte-vector ] if\r
+ ] unless ;\r
+ \r
+ M: byte-vector new-sequence\r
++ drop [ (byte-array) ] [ >fixnum ] bi byte-vector boa ;\r
+ \r
+ M: byte-vector equal?\r
+ over byte-vector? [ sequence= ] [ 2drop f ] if ;\r
+ \r
+ M: byte-array like\r
+ #! If we have an byte-array, we're done.\r
+ #! If we have a byte-vector, and it's at full capacity,\r
+ #! we're done. Otherwise, call resize-byte-array, which is a\r
+ #! relatively fast primitive.\r
+ drop dup byte-array? [\r
+ dup byte-vector? [\r
+ [ length ] [ underlying>> ] bi\r
+ 2dup length eq?\r
+ [ nip ] [ resize-byte-array ] if\r
+ ] [ >byte-array ] if\r
+ ] unless ;\r
+ \r
+ M: byte-array new-resizable drop <byte-vector> ;\r
+ \r
+ : BV{ \ } [ >byte-vector ] parse-literal ; parsing\r
+ \r
+ M: byte-vector pprint* pprint-object ;\r
+ M: byte-vector pprint-delims drop \ BV{ \ } ;\r
+ M: byte-vector >pprint-sequence ;\r
+ \r
+ INSTANCE: byte-vector growable\r
void primitive_tuple_boa(void);
void primitive_tuple_layout(void);
void primitive_byte_array(void);
+void primitive_uninitialized_byte_array(void);
void primitive_clone(void);
- F_ARRAY *reallot_array(F_ARRAY* array, CELL capacity, CELL fill);
+ F_ARRAY *reallot_array(F_ARRAY* array, CELL capacity);
F_BYTE_ARRAY *reallot_byte_array(F_BYTE_ARRAY *array, CELL capacity);
void primitive_resize_array(void);
void primitive_resize_byte_array(void);
F_STRING* allot_string_internal(CELL capacity);
F_STRING* allot_string(CELL capacity, CELL fill);
+void primitive_uninitialized_string(void);
void primitive_string(void);
- F_STRING *reallot_string(F_STRING *string, CELL capacity, CELL fill);
+ F_STRING *reallot_string(F_STRING *string, CELL capacity);
void primitive_resize_string(void);
F_STRING *memory_to_char_string(const char *string, CELL length);