src/buffer.c

changeset 543
7b9114030ca4
parent 542
45bcfd152f85
child 544
2e73456e5f84
equal deleted inserted replaced
542:45bcfd152f85 543:7b9114030ca4
138 void const *ptr, 138 void const *ptr,
139 size_t size, 139 size_t size,
140 size_t nitems, 140 size_t nitems,
141 CxBuffer *buffer 141 CxBuffer *buffer
142 ) { 142 ) {
143 // TODO: optimize for special case size == nitems == 1 143 // optimize for easy case
144 if (size == 1 && (buffer->capacity - buffer->pos) >= nitems) {
145 memcpy(buffer->bytes + buffer->pos, ptr, nitems);
146 buffer->pos += nitems;
147 if (buffer->pos > buffer->size) {
148 buffer->size = buffer->pos;
149 }
150 return nitems;
151 }
152
144 size_t len; 153 size_t len;
145 if (cx_szmul(size, nitems, &len)) { 154 if (cx_szmul(size, nitems, &len)) {
146 return 0; 155 return 0;
147 } 156 }
148 size_t required = buffer->pos + len; 157 size_t required = buffer->pos + len;

mercurial