# HG changeset patch # User Michael Pavone # Date 1406271157 25200 # Node ID 2a0a887997379272f147a3656d6fb61c2d2f4ab1 # Parent 9a30510f6e524ed8053213cf8a74524bcf7fcd14 A number of fixes and enhancmenets to "normal" bytearrays diff -r 9a30510f6e52 -r 2a0a88799737 modules/bytearray.tp --- a/modules/bytearray.tp Thu Jul 24 23:51:54 2014 -0700 +++ b/modules/bytearray.tp Thu Jul 24 23:52:37 2014 -0700 @@ -7,14 +7,14 @@ llProperty: bytes withType: uint32_t llProperty: buffer withType: (void ptr) llMessage: _init_buf withVars: { - sz <_ obj_int32 ptr + sz <- obj_int32 ptr } andCode: :sz { bytes <- sz num buffer <- GC_MALLOC_ATOMIC: bytes self } - llMessage: _buf_ptr withVArs: { + llMessage: _buf_ptr withVars: { ptrret <- cpointer ptr } andCode: { ptrret <- make_object: (addr_of: cpointer_meta) NULL 0 @@ -46,7 +46,16 @@ ret } - llMessage: stringFrom:to withVars:{ + llMessage: shrinkTo withVars: { + newsize <- obj_int32 ptr + } andCode: :newsize { + if: (newsize num) < bytes { + bytes <- newsize num + } + self + } + + llMessage: stringFrom:to withVars: { from <- obj_int32 ptr to <- obj_int32 ptr str <- string ptr @@ -56,20 +65,20 @@ str bytes!: (to num) - (from num) str len!: (str bytes) str data!: (GC_MALLOC_ATOMIC: (str bytes) + 1) - memcpy: (str data) buffer (str bytes) + memcpy: (str data) (buffer castTo: (uint8_t ptr)) + (from num) (str bytes) (str data) set: (str bytes) 0 str } string <- { - stringFrom: 0 to: + stringFrom: 0 to: length } - findChar:else <- :char found :else { + findChar:from:else <- :char :start found :else { notfound <- true n <- length - i <- 0 - while: { notFound && i < n } do: { + i <- start + while: { notfound && i < n } do: { if: (get: i) = char { notfound <- false } else: {