Blame SOURCES/7.4.600

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.600
22c937
Fcc: outbox
22c937
From: Bram Moolenaar <Bram@moolenaar.net>
22c937
Mime-Version: 1.0
22c937
Content-Type: text/plain; charset=UTF-8
22c937
Content-Transfer-Encoding: 8bit
22c937
------------
22c937
22c937
Patch 7.4.600
22c937
Problem:    Memory wasted in struct because of aligning.
22c937
Solution:   Split pos in lnum and col. (Dominique Pelle)
22c937
Files:	    src/regexp_nfa.c
22c937
22c937
22c937
*** ../vim-7.4.599/src/regexp_nfa.c	2015-01-27 14:39:55.661913204 +0100
22c937
--- src/regexp_nfa.c	2015-01-27 14:43:04.323847916 +0100
22c937
***************
22c937
*** 1456,1462 ****
22c937
  			 * matched an unlimited number of times. NFA_NOPEN is
22c937
  			 * added only once at a position, while NFA_SPLIT is
22c937
  			 * added multiple times.  This is more efficient than
22c937
! 			 * not allowsing NFA_SPLIT multiple times, it is used
22c937
  			 * a lot. */
22c937
  			EMIT(NFA_NOPEN);
22c937
  			break;
22c937
--- 1456,1462 ----
22c937
  			 * matched an unlimited number of times. NFA_NOPEN is
22c937
  			 * added only once at a position, while NFA_SPLIT is
22c937
  			 * added multiple times.  This is more efficient than
22c937
! 			 * not allowing NFA_SPLIT multiple times, it is used
22c937
  			 * a lot. */
22c937
  			EMIT(NFA_NOPEN);
22c937
  			break;
22c937
***************
22c937
*** 3726,3733 ****
22c937
      {
22c937
  	struct multipos
22c937
  	{
22c937
! 	    lpos_T	start;
22c937
! 	    lpos_T	end;
22c937
  	} multi[NSUBEXP];
22c937
  	struct linepos
22c937
  	{
22c937
--- 3726,3735 ----
22c937
      {
22c937
  	struct multipos
22c937
  	{
22c937
! 	    linenr_T	start_lnum;
22c937
! 	    linenr_T	end_lnum;
22c937
! 	    colnr_T	start_col;
22c937
! 	    colnr_T	end_col;
22c937
  	} multi[NSUBEXP];
22c937
  	struct linepos
22c937
  	{
22c937
***************
22c937
*** 3812,3821 ****
22c937
  	if (REG_MULTI)
22c937
  	    fprintf(log_fd, "*** group %d, start: c=%d, l=%d, end: c=%d, l=%d\n",
22c937
  		    j,
22c937
! 		    sub->list.multi[j].start.col,
22c937
! 		    (int)sub->list.multi[j].start.lnum,
22c937
! 		    sub->list.multi[j].end.col,
22c937
! 		    (int)sub->list.multi[j].end.lnum);
22c937
  	else
22c937
  	{
22c937
  	    char *s = (char *)sub->list.line[j].start;
22c937
--- 3814,3823 ----
22c937
  	if (REG_MULTI)
22c937
  	    fprintf(log_fd, "*** group %d, start: c=%d, l=%d, end: c=%d, l=%d\n",
22c937
  		    j,
22c937
! 		    sub->list.multi[j].start_col,
22c937
! 		    (int)sub->list.multi[j].start_lnum,
22c937
! 		    sub->list.multi[j].end_col,
22c937
! 		    (int)sub->list.multi[j].end_lnum);
22c937
  	else
22c937
  	{
22c937
  	    char *s = (char *)sub->list.line[j].start;
22c937
***************
22c937
*** 3952,3959 ****
22c937
      {
22c937
  	if (REG_MULTI)
22c937
  	{
22c937
! 	    if (from->list.multi[0].end.lnum >= 0)
22c937
! 		to->list.multi[0].end = from->list.multi[0].end;
22c937
  	}
22c937
  	else
22c937
  	{
22c937
--- 3954,3964 ----
22c937
      {
22c937
  	if (REG_MULTI)
22c937
  	{
22c937
! 	    if (from->list.multi[0].end_lnum >= 0)
22c937
!             {
22c937
! 		to->list.multi[0].end_lnum = from->list.multi[0].end_lnum;
22c937
! 		to->list.multi[0].end_col = from->list.multi[0].end_col;
22c937
!             }
22c937
  	}
22c937
  	else
22c937
  	{
22c937
***************
22c937
*** 3985,4017 ****
22c937
  	for (i = 0; i < todo; ++i)
22c937
  	{
22c937
  	    if (i < sub1->in_use)
22c937
! 		s1 = sub1->list.multi[i].start.lnum;
22c937
  	    else
22c937
  		s1 = -1;
22c937
  	    if (i < sub2->in_use)
22c937
! 		s2 = sub2->list.multi[i].start.lnum;
22c937
  	    else
22c937
  		s2 = -1;
22c937
  	    if (s1 != s2)
22c937
  		return FALSE;
22c937
! 	    if (s1 != -1 && sub1->list.multi[i].start.col
22c937
! 					     != sub2->list.multi[i].start.col)
22c937
  		return FALSE;
22c937
  
22c937
  	    if (nfa_has_backref)
22c937
  	    {
22c937
  		if (i < sub1->in_use)
22c937
! 		    s1 = sub1->list.multi[i].end.lnum;
22c937
  		else
22c937
  		    s1 = -1;
22c937
  		if (i < sub2->in_use)
22c937
! 		    s2 = sub2->list.multi[i].end.lnum;
22c937
  		else
22c937
  		    s2 = -1;
22c937
  		if (s1 != s2)
22c937
  		    return FALSE;
22c937
! 		if (s1 != -1 && sub1->list.multi[i].end.col
22c937
! 					       != sub2->list.multi[i].end.col)
22c937
  		return FALSE;
22c937
  	    }
22c937
  	}
22c937
--- 3990,4022 ----
22c937
  	for (i = 0; i < todo; ++i)
22c937
  	{
22c937
  	    if (i < sub1->in_use)
22c937
! 		s1 = sub1->list.multi[i].start_lnum;
22c937
  	    else
22c937
  		s1 = -1;
22c937
  	    if (i < sub2->in_use)
22c937
! 		s2 = sub2->list.multi[i].start_lnum;
22c937
  	    else
22c937
  		s2 = -1;
22c937
  	    if (s1 != s2)
22c937
  		return FALSE;
22c937
! 	    if (s1 != -1 && sub1->list.multi[i].start_col
22c937
! 					     != sub2->list.multi[i].start_col)
22c937
  		return FALSE;
22c937
  
22c937
  	    if (nfa_has_backref)
22c937
  	    {
22c937
  		if (i < sub1->in_use)
22c937
! 		    s1 = sub1->list.multi[i].end_lnum;
22c937
  		else
22c937
  		    s1 = -1;
22c937
  		if (i < sub2->in_use)
22c937
! 		    s2 = sub2->list.multi[i].end_lnum;
22c937
  		else
22c937
  		    s2 = -1;
22c937
  		if (s1 != s2)
22c937
  		    return FALSE;
22c937
! 		if (s1 != -1 && sub1->list.multi[i].end_col
22c937
! 					       != sub2->list.multi[i].end_col)
22c937
  		return FALSE;
22c937
  	    }
22c937
  	}
22c937
***************
22c937
*** 4062,4068 ****
22c937
      if (sub->in_use <= 0)
22c937
  	col = -1;
22c937
      else if (REG_MULTI)
22c937
! 	col = sub->list.multi[0].start.col;
22c937
      else
22c937
  	col = (int)(sub->list.line[0].start - regline);
22c937
      nfa_set_code(state->c);
22c937
--- 4067,4073 ----
22c937
      if (sub->in_use <= 0)
22c937
  	col = -1;
22c937
      else if (REG_MULTI)
22c937
! 	col = sub->list.multi[0].start_col;
22c937
      else
22c937
  	col = (int)(sub->list.line[0].start - regline);
22c937
      nfa_set_code(state->c);
22c937
***************
22c937
*** 4482,4488 ****
22c937
  	    {
22c937
  		if (subidx < sub->in_use)
22c937
  		{
22c937
! 		    save_lpos = sub->list.multi[subidx].start;
22c937
  		    save_in_use = -1;
22c937
  		}
22c937
  		else
22c937
--- 4487,4494 ----
22c937
  	    {
22c937
  		if (subidx < sub->in_use)
22c937
  		{
22c937
! 		    save_lpos.lnum = sub->list.multi[subidx].start_lnum;
22c937
! 		    save_lpos.col = sub->list.multi[subidx].start_col;
22c937
  		    save_in_use = -1;
22c937
  		}
22c937
  		else
22c937
***************
22c937
*** 4490,4509 ****
22c937
  		    save_in_use = sub->in_use;
22c937
  		    for (i = sub->in_use; i < subidx; ++i)
22c937
  		    {
22c937
! 			sub->list.multi[i].start.lnum = -1;
22c937
! 			sub->list.multi[i].end.lnum = -1;
22c937
  		    }
22c937
  		    sub->in_use = subidx + 1;
22c937
  		}
22c937
  		if (off == -1)
22c937
  		{
22c937
! 		    sub->list.multi[subidx].start.lnum = reglnum + 1;
22c937
! 		    sub->list.multi[subidx].start.col = 0;
22c937
  		}
22c937
  		else
22c937
  		{
22c937
! 		    sub->list.multi[subidx].start.lnum = reglnum;
22c937
! 		    sub->list.multi[subidx].start.col =
22c937
  					  (colnr_T)(reginput - regline + off);
22c937
  		}
22c937
  	    }
22c937
--- 4496,4515 ----
22c937
  		    save_in_use = sub->in_use;
22c937
  		    for (i = sub->in_use; i < subidx; ++i)
22c937
  		    {
22c937
! 			sub->list.multi[i].start_lnum = -1;
22c937
! 			sub->list.multi[i].end_lnum = -1;
22c937
  		    }
22c937
  		    sub->in_use = subidx + 1;
22c937
  		}
22c937
  		if (off == -1)
22c937
  		{
22c937
! 		    sub->list.multi[subidx].start_lnum = reglnum + 1;
22c937
! 		    sub->list.multi[subidx].start_col = 0;
22c937
  		}
22c937
  		else
22c937
  		{
22c937
! 		    sub->list.multi[subidx].start_lnum = reglnum;
22c937
! 		    sub->list.multi[subidx].start_col =
22c937
  					  (colnr_T)(reginput - regline + off);
22c937
  		}
22c937
  	    }
22c937
***************
22c937
*** 4539,4545 ****
22c937
  	    if (save_in_use == -1)
22c937
  	    {
22c937
  		if (REG_MULTI)
22c937
! 		    sub->list.multi[subidx].start = save_lpos;
22c937
  		else
22c937
  		    sub->list.line[subidx].start = save_ptr;
22c937
  	    }
22c937
--- 4545,4554 ----
22c937
  	    if (save_in_use == -1)
22c937
  	    {
22c937
  		if (REG_MULTI)
22c937
!                 {
22c937
! 		    sub->list.multi[subidx].start_lnum = save_lpos.lnum;
22c937
! 		    sub->list.multi[subidx].start_col = save_lpos.col;
22c937
!                 }
22c937
  		else
22c937
  		    sub->list.line[subidx].start = save_ptr;
22c937
  	    }
22c937
***************
22c937
*** 4549,4555 ****
22c937
  
22c937
  	case NFA_MCLOSE:
22c937
  	    if (nfa_has_zend && (REG_MULTI
22c937
! 			? subs->norm.list.multi[0].end.lnum >= 0
22c937
  			: subs->norm.list.line[0].end != NULL))
22c937
  	    {
22c937
  		/* Do not overwrite the position set by \ze. */
22c937
--- 4558,4564 ----
22c937
  
22c937
  	case NFA_MCLOSE:
22c937
  	    if (nfa_has_zend && (REG_MULTI
22c937
! 			? subs->norm.list.multi[0].end_lnum >= 0
22c937
  			: subs->norm.list.line[0].end != NULL))
22c937
  	    {
22c937
  		/* Do not overwrite the position set by \ze. */
22c937
***************
22c937
*** 4603,4618 ****
22c937
  		sub->in_use = subidx + 1;
22c937
  	    if (REG_MULTI)
22c937
  	    {
22c937
! 		save_lpos = sub->list.multi[subidx].end;
22c937
  		if (off == -1)
22c937
  		{
22c937
! 		    sub->list.multi[subidx].end.lnum = reglnum + 1;
22c937
! 		    sub->list.multi[subidx].end.col = 0;
22c937
  		}
22c937
  		else
22c937
  		{
22c937
! 		    sub->list.multi[subidx].end.lnum = reglnum;
22c937
! 		    sub->list.multi[subidx].end.col =
22c937
  					  (colnr_T)(reginput - regline + off);
22c937
  		}
22c937
  		/* avoid compiler warnings */
22c937
--- 4612,4628 ----
22c937
  		sub->in_use = subidx + 1;
22c937
  	    if (REG_MULTI)
22c937
  	    {
22c937
! 		save_lpos.lnum = sub->list.multi[subidx].end_lnum;
22c937
! 		save_lpos.col = sub->list.multi[subidx].end_col;
22c937
  		if (off == -1)
22c937
  		{
22c937
! 		    sub->list.multi[subidx].end_lnum = reglnum + 1;
22c937
! 		    sub->list.multi[subidx].end_col = 0;
22c937
  		}
22c937
  		else
22c937
  		{
22c937
! 		    sub->list.multi[subidx].end_lnum = reglnum;
22c937
! 		    sub->list.multi[subidx].end_col =
22c937
  					  (colnr_T)(reginput - regline + off);
22c937
  		}
22c937
  		/* avoid compiler warnings */
22c937
***************
22c937
*** 4637,4643 ****
22c937
  		sub = &subs->norm;
22c937
  
22c937
  	    if (REG_MULTI)
22c937
! 		sub->list.multi[subidx].end = save_lpos;
22c937
  	    else
22c937
  		sub->list.line[subidx].end = save_ptr;
22c937
  	    sub->in_use = save_in_use;
22c937
--- 4647,4656 ----
22c937
  		sub = &subs->norm;
22c937
  
22c937
  	    if (REG_MULTI)
22c937
!             {
22c937
! 		sub->list.multi[subidx].end_lnum = save_lpos.lnum;
22c937
! 		sub->list.multi[subidx].end_col = save_lpos.col;
22c937
!             }
22c937
  	    else
22c937
  		sub->list.line[subidx].end = save_ptr;
22c937
  	    sub->in_use = save_in_use;
22c937
***************
22c937
*** 4825,4839 ****
22c937
  
22c937
      if (REG_MULTI)
22c937
      {
22c937
! 	if (sub->list.multi[subidx].start.lnum < 0
22c937
! 				       || sub->list.multi[subidx].end.lnum < 0)
22c937
  	    goto retempty;
22c937
! 	if (sub->list.multi[subidx].start.lnum == reglnum
22c937
! 			       && sub->list.multi[subidx].end.lnum == reglnum)
22c937
  	{
22c937
! 	    len = sub->list.multi[subidx].end.col
22c937
! 					  - sub->list.multi[subidx].start.col;
22c937
! 	    if (cstrncmp(regline + sub->list.multi[subidx].start.col,
22c937
  							 reginput, &len) == 0)
22c937
  	    {
22c937
  		*bytelen = len;
22c937
--- 4838,4852 ----
22c937
  
22c937
      if (REG_MULTI)
22c937
      {
22c937
! 	if (sub->list.multi[subidx].start_lnum < 0
22c937
! 				       || sub->list.multi[subidx].end_lnum < 0)
22c937
  	    goto retempty;
22c937
! 	if (sub->list.multi[subidx].start_lnum == reglnum
22c937
! 			       && sub->list.multi[subidx].end_lnum == reglnum)
22c937
  	{
22c937
! 	    len = sub->list.multi[subidx].end_col
22c937
! 					  - sub->list.multi[subidx].start_col;
22c937
! 	    if (cstrncmp(regline + sub->list.multi[subidx].start_col,
22c937
  							 reginput, &len) == 0)
22c937
  	    {
22c937
  		*bytelen = len;
22c937
***************
22c937
*** 4843,4852 ****
22c937
  	else
22c937
  	{
22c937
  	    if (match_with_backref(
22c937
! 			sub->list.multi[subidx].start.lnum,
22c937
! 			sub->list.multi[subidx].start.col,
22c937
! 			sub->list.multi[subidx].end.lnum,
22c937
! 			sub->list.multi[subidx].end.col,
22c937
  			bytelen) == RA_MATCH)
22c937
  		return TRUE;
22c937
  	}
22c937
--- 4856,4865 ----
22c937
  	else
22c937
  	{
22c937
  	    if (match_with_backref(
22c937
! 			sub->list.multi[subidx].start_lnum,
22c937
! 			sub->list.multi[subidx].start_col,
22c937
! 			sub->list.multi[subidx].end_lnum,
22c937
! 			sub->list.multi[subidx].end_col,
22c937
  			bytelen) == RA_MATCH)
22c937
  		return TRUE;
22c937
  	}
22c937
***************
22c937
*** 5441,5446 ****
22c937
--- 5454,5460 ----
22c937
  
22c937
      /* Allocate memory for the lists of nodes. */
22c937
      size = (nstate + 1) * sizeof(nfa_thread_T);
22c937
+ 
22c937
      list[0].t = (nfa_thread_T *)lalloc(size, TRUE);
22c937
      list[0].len = nstate + 1;
22c937
      list[1].t = (nfa_thread_T *)lalloc(size, TRUE);
22c937
***************
22c937
*** 5482,5489 ****
22c937
      {
22c937
  	if (REG_MULTI)
22c937
  	{
22c937
! 	    m->norm.list.multi[0].start.lnum = reglnum;
22c937
! 	    m->norm.list.multi[0].start.col = (colnr_T)(reginput - regline);
22c937
  	}
22c937
  	else
22c937
  	    m->norm.list.line[0].start = reginput;
22c937
--- 5496,5503 ----
22c937
      {
22c937
  	if (REG_MULTI)
22c937
  	{
22c937
! 	    m->norm.list.multi[0].start_lnum = reglnum;
22c937
! 	    m->norm.list.multi[0].start_col = (colnr_T)(reginput - regline);
22c937
  	}
22c937
  	else
22c937
  	    m->norm.list.line[0].start = reginput;
22c937
***************
22c937
*** 5580,5586 ****
22c937
  		if (t->subs.norm.in_use <= 0)
22c937
  		    col = -1;
22c937
  		else if (REG_MULTI)
22c937
! 		    col = t->subs.norm.list.multi[0].start.col;
22c937
  		else
22c937
  		    col = (int)(t->subs.norm.list.line[0].start - regline);
22c937
  		nfa_set_code(t->state->c);
22c937
--- 5594,5600 ----
22c937
  		if (t->subs.norm.in_use <= 0)
22c937
  		    col = -1;
22c937
  		else if (REG_MULTI)
22c937
! 		    col = t->subs.norm.list.multi[0].start_col;
22c937
  		else
22c937
  		    col = (int)(t->subs.norm.list.line[0].start - regline);
22c937
  		nfa_set_code(t->state->c);
22c937
***************
22c937
*** 5861,5867 ****
22c937
  		     * continue with what follows. */
22c937
  		    if (REG_MULTI)
22c937
  			/* TODO: multi-line match */
22c937
! 			bytelen = m->norm.list.multi[0].end.col
22c937
  						  - (int)(reginput - regline);
22c937
  		    else
22c937
  			bytelen = (int)(m->norm.list.line[0].end - reginput);
22c937
--- 5875,5881 ----
22c937
  		     * continue with what follows. */
22c937
  		    if (REG_MULTI)
22c937
  			/* TODO: multi-line match */
22c937
! 			bytelen = m->norm.list.multi[0].end_col
22c937
  						  - (int)(reginput - regline);
22c937
  		    else
22c937
  			bytelen = (int)(m->norm.list.line[0].end - reginput);
22c937
***************
22c937
*** 6741,6747 ****
22c937
  		if (add)
22c937
  		{
22c937
  		    if (REG_MULTI)
22c937
! 			m->norm.list.multi[0].start.col =
22c937
  					 (colnr_T)(reginput - regline) + clen;
22c937
  		    else
22c937
  			m->norm.list.line[0].start = reginput + clen;
22c937
--- 6755,6761 ----
22c937
  		if (add)
22c937
  		{
22c937
  		    if (REG_MULTI)
22c937
! 			m->norm.list.multi[0].start_col =
22c937
  					 (colnr_T)(reginput - regline) + clen;
22c937
  		    else
22c937
  			m->norm.list.line[0].start = reginput + clen;
22c937
***************
22c937
*** 6854,6861 ****
22c937
      {
22c937
  	for (i = 0; i < subs.norm.in_use; i++)
22c937
  	{
22c937
! 	    reg_startpos[i] = subs.norm.list.multi[i].start;
22c937
! 	    reg_endpos[i] = subs.norm.list.multi[i].end;
22c937
  	}
22c937
  
22c937
  	if (reg_startpos[0].lnum < 0)
22c937
--- 6868,6878 ----
22c937
      {
22c937
  	for (i = 0; i < subs.norm.in_use; i++)
22c937
  	{
22c937
! 	    reg_startpos[i].lnum = subs.norm.list.multi[i].start_lnum;
22c937
! 	    reg_startpos[i].col = subs.norm.list.multi[i].start_col;
22c937
! 
22c937
! 	    reg_endpos[i].lnum = subs.norm.list.multi[i].end_lnum;
22c937
! 	    reg_endpos[i].col = subs.norm.list.multi[i].end_col;
22c937
  	}
22c937
  
22c937
  	if (reg_startpos[0].lnum < 0)
22c937
***************
22c937
*** 6903,6915 ****
22c937
  		struct multipos *mpos = &subs.synt.list.multi[i];
22c937
  
22c937
  		/* Only accept single line matches that are valid. */
22c937
! 		if (mpos->start.lnum >= 0
22c937
! 			&& mpos->start.lnum == mpos->end.lnum
22c937
! 			&& mpos->end.col >= mpos->start.col)
22c937
  		    re_extmatch_out->matches[i] =
22c937
! 			vim_strnsave(reg_getline(mpos->start.lnum)
22c937
! 							    + mpos->start.col,
22c937
! 					     mpos->end.col - mpos->start.col);
22c937
  	    }
22c937
  	    else
22c937
  	    {
22c937
--- 6920,6932 ----
22c937
  		struct multipos *mpos = &subs.synt.list.multi[i];
22c937
  
22c937
  		/* Only accept single line matches that are valid. */
22c937
! 		if (mpos->start_lnum >= 0
22c937
! 			&& mpos->start_lnum == mpos->end_lnum
22c937
! 			&& mpos->end_col >= mpos->start_col)
22c937
  		    re_extmatch_out->matches[i] =
22c937
! 			vim_strnsave(reg_getline(mpos->start_lnum)
22c937
! 							    + mpos->start_col,
22c937
! 					     mpos->end_col - mpos->start_col);
22c937
  	    }
22c937
  	    else
22c937
  	    {
22c937
*** ../vim-7.4.599/src/version.c	2015-01-27 14:39:55.661913204 +0100
22c937
--- src/version.c	2015-01-27 14:44:06.739164665 +0100
22c937
***************
22c937
*** 743,744 ****
22c937
--- 743,746 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     600,
22c937
  /**/
22c937
22c937
-- 
22c937
hundred-and-one symptoms of being an internet addict:
22c937
126. You brag to all of your friends about your date Saturday night...but
22c937
     you don't tell them it was only in a chat room.
22c937
22c937
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
22c937
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
22c937
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
22c937
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///