|
|
| version 1.92, 2024/09/14 22:58:50 | version 1.93, 2024/09/15 00:38:27 |
|---|---|
| Line 100 public: | Line 100 public: |
| /// append to array | /// append to array |
| inline Array& operator+=(T src) { | inline Array& operator+=(T src) { |
| if(is_full()) | if(is_full()) |
| expand(fallocated>0? 2+fallocated/32 : 3); // 3 is PAF default, confirmed by tests | expand(); |
| felements[fused++]=src; | felements[fused++]=src; |
| Line 122 public: | Line 122 public: |
| if(limit==ARRAY_OPTION_LIMIT_ALL || limit>m) | if(limit==ARRAY_OPTION_LIMIT_ALL || limit>m) |
| limit=m; | limit=m; |
| ssize_t delta=limit-(fallocated-fused); | size_t required=fused+limit; |
| if(delta>0) | if(required>fallocated) |
| expand(delta); | resize(required); |
| T* from=&src.felements[offset]; | T* from=&src.felements[offset]; |
| T* to=&felements[fused]; | T* to=&felements[fused]; |
| for(T* from_end=from+limit; from<from_end; from++) | for(T* from_end=from+limit; from<from_end;) |
| *to++=*from; | *to++=*from++; |
| fused+=limit; | fused+=limit; |
| return *this; | return *this; |
| } | } |
| Line 157 public: | Line 157 public: |
| assert(index<=count()); | assert(index<=count()); |
| if(is_full()) | if(is_full()) |
| expand(fallocated>0? 2+fallocated/32 : 3); // 3 is PAF default, confirmed by tests | expand(); |
| memmove(felements+index+1, felements+index, (fused-index) * sizeof(T)); | memmove(felements+index+1, felements+index, (fused-index) * sizeof(T)); |
| Line 222 protected: | Line 222 protected: |
| return fused == fallocated; | return fused == fallocated; |
| } | } |
| void expand(size_t delta) { | inline void expand() { |
| resize(fallocated>0 ? fallocated+fallocated/4+2 : 3); // 3 is PAF default, confirmed by tests | |
| } | |
| void resize(size_t asize) { | |
| if(fallocated){ | if(fallocated){ |
| size_t new_allocated=fallocated+delta; | felements=(T *)pa_realloc(felements, asize*sizeof(T)); |
| felements=(T *)pa_realloc(felements, new_allocated*sizeof(T)); | fallocated=asize; |
| fallocated=new_allocated; | |
| } else { | } else { |
| fallocated=delta; | fallocated=asize; |
| felements=(T *)pa_malloc(fallocated*sizeof(T)); | felements=(T *)pa_malloc(asize*sizeof(T)); |
| } | } |
| } | } |