Mercurial > vim
comparison src/blob.c @ 17530:ef23ec1eee54 v8.1.1763
patch 8.1.1763: evalfunc.c is still too big
commit https://github.com/vim/vim/commit/9f9fe37f6750f342255a51f158a7bb372c827f7f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 27 23:12:12 2019 +0200
patch 8.1.1763: evalfunc.c is still too big
Problem: Evalfunc.c is still too big.
Solution: Move dict and list functions to a better place.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 27 Jul 2019 23:15:05 +0200 |
parents | a0eb2ff0f297 |
children | c469e1930456 |
comparison
equal
deleted
inserted
replaced
17529:4bd2e3339ba3 | 17530:ef23ec1eee54 |
---|---|
256 failed: | 256 failed: |
257 blob_free(blob); | 257 blob_free(blob); |
258 return NULL; | 258 return NULL; |
259 } | 259 } |
260 | 260 |
261 /* | |
262 * "remove({blob})" function | |
263 */ | |
264 void | |
265 blob_remove(typval_T *argvars, typval_T *rettv) | |
266 { | |
267 int error = FALSE; | |
268 long idx = (long)tv_get_number_chk(&argvars[1], &error); | |
269 long end; | |
270 | |
271 if (!error) | |
272 { | |
273 blob_T *b = argvars[0].vval.v_blob; | |
274 int len = blob_len(b); | |
275 char_u *p; | |
276 | |
277 if (idx < 0) | |
278 // count from the end | |
279 idx = len + idx; | |
280 if (idx < 0 || idx >= len) | |
281 { | |
282 semsg(_(e_blobidx), idx); | |
283 return; | |
284 } | |
285 if (argvars[2].v_type == VAR_UNKNOWN) | |
286 { | |
287 // Remove one item, return its value. | |
288 p = (char_u *)b->bv_ga.ga_data; | |
289 rettv->vval.v_number = (varnumber_T) *(p + idx); | |
290 mch_memmove(p + idx, p + idx + 1, (size_t)len - idx - 1); | |
291 --b->bv_ga.ga_len; | |
292 } | |
293 else | |
294 { | |
295 blob_T *blob; | |
296 | |
297 // Remove range of items, return list with values. | |
298 end = (long)tv_get_number_chk(&argvars[2], &error); | |
299 if (error) | |
300 return; | |
301 if (end < 0) | |
302 // count from the end | |
303 end = len + end; | |
304 if (end >= len || idx > end) | |
305 { | |
306 semsg(_(e_blobidx), end); | |
307 return; | |
308 } | |
309 blob = blob_alloc(); | |
310 if (blob == NULL) | |
311 return; | |
312 blob->bv_ga.ga_len = end - idx + 1; | |
313 if (ga_grow(&blob->bv_ga, end - idx + 1) == FAIL) | |
314 { | |
315 vim_free(blob); | |
316 return; | |
317 } | |
318 p = (char_u *)b->bv_ga.ga_data; | |
319 mch_memmove((char_u *)blob->bv_ga.ga_data, p + idx, | |
320 (size_t)(end - idx + 1)); | |
321 ++blob->bv_refcount; | |
322 rettv->v_type = VAR_BLOB; | |
323 rettv->vval.v_blob = blob; | |
324 | |
325 mch_memmove(p + idx, p + end + 1, (size_t)(len - end)); | |
326 b->bv_ga.ga_len -= end - idx + 1; | |
327 } | |
328 } | |
329 } | |
330 | |
261 #endif /* defined(FEAT_EVAL) */ | 331 #endif /* defined(FEAT_EVAL) */ |