summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-06-04 19:17:07 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-04 19:17:07 +0200
commit6c4c404c580fadd69e39297a6cb4b214f2fcb6d6 (patch)
tree4fd835215e5589a5cebc118a63c0d46e8a81c18d
parent24951a67c24e75ec4ff7506f8e2e789ccd786e89 (diff)
patch 8.2.2935: calculating register width is not always neededv8.2.2935
Problem: Calculating register width is not always needed. (Christian Brabandt) Solution: Only calculate the width when the type is MBLOCK.
-rw-r--r--src/register.c20
-rw-r--r--src/version.c2
2 files changed, 14 insertions, 8 deletions
diff --git a/src/register.c b/src/register.c
index 8c951b7eab..5dc8f2896a 100644
--- a/src/register.c
+++ b/src/register.c
@@ -2836,7 +2836,6 @@ str_to_reg(
char_u **ss;
char_u **pp;
long maxlen;
- int charlen;
if (y_ptr->y_array == NULL) // NULL means empty register
y_ptr->y_size = 0;
@@ -2895,23 +2894,28 @@ str_to_reg(
{
for (ss = (char_u **) str; *ss != NULL; ++ss, ++lnum)
{
- charlen = MB_CHARLEN(*ss);
- i = (long)STRLEN(*ss);
- pp[lnum] = vim_strnsave(*ss, i);
- if (charlen > maxlen)
- maxlen = charlen;
+ pp[lnum] = vim_strsave(*ss);
+ if (type == MBLOCK)
+ {
+ int charlen = mb_string2cells(*ss, -1);
+
+ if (charlen > maxlen)
+ maxlen = charlen;
+ }
}
}
else
{
for (start = 0; start < len + extraline; start += i + 1)
{
- charlen = 0;
+ int charlen = 0;
+
for (i = start; i < len; ++i) // find the end of the line
{
if (str[i] == '\n')
break;
- charlen += mb_ptr2cells_len(str + i, len - i);
+ if (type == MBLOCK)
+ charlen += mb_ptr2cells_len(str + i, len - i);
}
i -= start; // i is now length of line
if (charlen > maxlen)
diff --git a/src/version.c b/src/version.c
index eab59f42ef..d55bb30ce3 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2935,
+/**/
2934,
/**/
2933,
ground-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* $OpenBSD$ */

/*
 * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>
#include <sys/stat.h>

#include <event.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "tmux.h"

char *
osdep_get_name(int fd, __unused char *tty)
{
	FILE	*f;
	char	*path, *buf;
	size_t	 len;
	int	 ch;
	pid_t	 pgrp;

	if ((pgrp = tcgetpgrp(fd)) == -1)
		return (NULL);

	xasprintf(&path, "/proc/%lld/cmdline", (long long) pgrp);
	if ((f = fopen(path, "r")) == NULL) {
		free(path);
		return (NULL);
	}
	free(path);

	len = 0;
	buf = NULL;
	while ((ch = fgetc(f)) != EOF) {
		if (ch == '\0')
			break;
		buf = xrealloc(buf, len + 2);
		buf[len++] = ch;
	}
	if (buf != NULL)
		buf[len] = '\0';

	fclose(f);
	return (buf);
}

char *
osdep_get_cwd(int fd)
{
	static char	 target[MAXPATHLEN + 1];
	char		*path;
	pid_t		 pgrp;
	ssize_t		 n;

	if ((pgrp = tcgetpgrp(fd)) == -1)
		return (NULL);

	xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp);
	n = readlink(path, target, MAXPATHLEN);
	free(path);
	if (n > 0) {
		target[n] = '\0';
		return (target);
	}
	return (NULL);
}

struct event_base *
osdep_event_init(void)
{
	return (event_init());
}