]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/byte_arrays.hpp
io.streams.256color: faster by caching styles
[factor.git] / vm / byte_arrays.hpp
old mode 100755 (executable)
new mode 100644 (file)
index 0817f7d..2978d94
@@ -1,29 +1,27 @@
-namespace factor
-{
+namespace factor {
 
 struct growable_byte_array {
-       cell count;
-       gc_root<byte_array> elements;
+  cell count;
+  data_root<byte_array> elements;
 
-       explicit growable_byte_array(factor_vm *parent,cell capacity = 40) : count(0), elements(parent->allot_byte_array(capacity),parent) { }
+  // Allocates memory
+  growable_byte_array(factor_vm* parent, cell capacity = 40)
+      : count(0), elements(parent->allot_byte_array(capacity), parent) {}
 
-       void append_bytes(void *elts, cell len);
-       void append_byte_array(cell elts);
+  void reallot_array(cell count);
+  void grow_bytes(cell len);
+  void append_bytes(void* elts, cell len);
+  void append_byte_array(cell elts);
 
-       void trim();
+  void trim();
 };
 
-template<typename Type> byte_array *factor_vm::byte_array_from_value(Type *value)
-{
-       return byte_array_from_values(value,1);
-}
-
-template<typename Type> byte_array *factor_vm::byte_array_from_values(Type *values, cell len)
-{
-       cell size = sizeof(Type) * len;
-       byte_array *data = allot_uninitialized_array<byte_array>(size);
-       memcpy(data->data<char>(),values,size);
-       return data;
+// Allocates memory
+template <typename Type>
+byte_array* factor_vm::byte_array_from_value(Type* value) {
+  byte_array* data = allot_uninitialized_array<byte_array>(sizeof(Type));
+  memcpy(data->data<char>(), value, sizeof(Type));
+  return data;
 }
 
 }