comparison src/vim9expr.c @ 28287:dc68c111cf7a v8.2.4669

patch 8.2.4669: in compiled code len('string') is not inlined Commit: https://github.com/vim/vim/commit/58f331a05f5b7bdddf04e68b6e51a827fd0c43f0 Author: LemonBoy <thatlemon@gmail.com> Date: Sat Apr 2 21:59:06 2022 +0100 patch 8.2.4669: in compiled code len('string') is not inlined Problem: In compiled code len('string') is not inlined. Solution: Compute the length at compile time if possible. (closes https://github.com/vim/vim/issues/10065)
author Bram Moolenaar <Bram@vim.org>
date Sat, 02 Apr 2022 23:00:05 +0200
parents c84f4e34ba16
children d550054e1328
comparison
equal deleted inserted replaced
28286:68700da20991 28287:dc68c111cf7a
722 semsg(_(e_cannot_use_str_itself_it_is_imported), namebuf); 722 semsg(_(e_cannot_use_str_itself_it_is_imported), namebuf);
723 return FAIL; 723 return FAIL;
724 } 724 }
725 725
726 // We can evaluate "has('name')" at compile time. 726 // We can evaluate "has('name')" at compile time.
727 // We can evaluate "len('string')" at compile time.
727 // We always evaluate "exists_compiled()" at compile time. 728 // We always evaluate "exists_compiled()" at compile time.
728 if ((varlen == 3 && STRNCMP(*arg, "has", 3) == 0) 729 if ((varlen == 3
730 && (STRNCMP(*arg, "has", 3) == 0 || STRNCMP(*arg, "len", 3) == 0))
729 || (varlen == 15 && STRNCMP(*arg, "exists_compiled", 6) == 0)) 731 || (varlen == 15 && STRNCMP(*arg, "exists_compiled", 6) == 0))
730 { 732 {
731 char_u *s = skipwhite(*arg + varlen + 1); 733 char_u *s = skipwhite(*arg + varlen + 1);
732 typval_T argvars[2]; 734 typval_T argvars[2];
733 int is_has = **arg == 'h'; 735 int is_has = **arg == 'h';
736 int is_len = **arg == 'l';
734 737
735 argvars[0].v_type = VAR_UNKNOWN; 738 argvars[0].v_type = VAR_UNKNOWN;
736 if (*s == '"') 739 if (*s == '"')
737 (void)eval_string(&s, &argvars[0], TRUE); 740 (void)eval_string(&s, &argvars[0], TRUE);
738 else if (*s == '\'') 741 else if (*s == '\'')
748 argvars[1].v_type = VAR_UNKNOWN; 751 argvars[1].v_type = VAR_UNKNOWN;
749 tv->v_type = VAR_NUMBER; 752 tv->v_type = VAR_NUMBER;
750 tv->vval.v_number = 0; 753 tv->vval.v_number = 0;
751 if (is_has) 754 if (is_has)
752 f_has(argvars, tv); 755 f_has(argvars, tv);
756 else if (is_len)
757 f_len(argvars, tv);
753 else 758 else
754 f_exists(argvars, tv); 759 f_exists(argvars, tv);
755 clear_tv(&argvars[0]); 760 clear_tv(&argvars[0]);
756 ++ppconst->pp_used; 761 ++ppconst->pp_used;
757 return OK; 762 return OK;
758 } 763 }
759 clear_tv(&argvars[0]); 764 clear_tv(&argvars[0]);
760 if (!is_has) 765 if (!is_has && !is_len)
761 { 766 {
762 emsg(_(e_argument_of_exists_compiled_must_be_literal_string)); 767 emsg(_(e_argument_of_exists_compiled_must_be_literal_string));
763 return FAIL; 768 return FAIL;
764 } 769 }
765 } 770 }