comparison src/userfunc.c @ 9655:f1920505bc16 v7.4.2104

commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jul 26 20:46:08 2016 +0200 patch 7.4.2104 Problem: Code duplication when unreferencing a function. Solution: De-duplicate.
author Christian Brabandt <cb@256bit.org>
date Tue, 26 Jul 2016 21:00:08 +0200
parents af0d98d8836e
children 8c2553beff0f
comparison
equal deleted inserted replaced
9654:9335bbb35ee8 9655:f1920505bc16
2638 * becomes zero. Only for numbered functions. 2638 * becomes zero. Only for numbered functions.
2639 */ 2639 */
2640 void 2640 void
2641 func_unref(char_u *name) 2641 func_unref(char_u *name)
2642 { 2642 {
2643 ufunc_T *fp; 2643 ufunc_T *fp = NULL;
2644 2644
2645 if (name == NULL) 2645 if (name == NULL)
2646 return; 2646 return;
2647 else if (isdigit(*name)) 2647 if (isdigit(*name))
2648 { 2648 {
2649 fp = find_func(name); 2649 fp = find_func(name);
2650 if (fp == NULL) 2650 if (fp == NULL)
2651 { 2651 {
2652 #ifdef EXITFREE 2652 #ifdef EXITFREE
2653 if (!entered_free_all_mem) 2653 if (!entered_free_all_mem)
2654 #endif 2654 #endif
2655 EMSG2(_(e_intern2), "func_unref()"); 2655 EMSG2(_(e_intern2), "func_unref()");
2656 } 2656 }
2657 else if (--fp->uf_refcount <= 0)
2658 {
2659 /* Only delete it when it's not being used. Otherwise it's done
2660 * when "uf_calls" becomes zero. */
2661 if (fp->uf_calls == 0)
2662 func_free(fp);
2663 }
2664 } 2657 }
2665 else if (STRNCMP(name, "<lambda>", 8) == 0) 2658 else if (STRNCMP(name, "<lambda>", 8) == 0)
2666 { 2659 {
2667 /* fail silently, when lambda function isn't found. */ 2660 /* fail silently, when lambda function isn't found. */
2668 fp = find_func(name); 2661 fp = find_func(name);
2669 if (fp != NULL && --fp->uf_refcount <= 0) 2662 }
2670 { 2663 if (fp != NULL && --fp->uf_refcount <= 0)
2671 /* Only delete it when it's not being used. Otherwise it's done 2664 {
2672 * when "uf_calls" becomes zero. */ 2665 /* Only delete it when it's not being used. Otherwise it's done
2673 if (fp->uf_calls == 0) 2666 * when "uf_calls" becomes zero. */
2674 func_free(fp); 2667 if (fp->uf_calls == 0)
2675 } 2668 func_free(fp);
2676 } 2669 }
2677 } 2670 }
2678 2671
2679 /* 2672 /*
2680 * Count a reference to a Function. 2673 * Count a reference to a Function.