A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/vim/vim/commit/126bc4690fb94c6628c704a3044bbc58d84dec42 below:

Clipboard code can be improved · vim/vim@126bc46 · GitHub

@@ -47,8 +47,12 @@ static const char *supported_mimes[] = {

47 47 48 48

static void clip_wl_receive_data(Clipboard_T *cbd,

49 49

const char *mime_type, int fd);

50 +

static void clip_wl_request_selection(Clipboard_T *cbd);

50 51

static void clip_wl_send_data(const char *mime_type, int fd,

51 52

wayland_selection_T);

53 +

static int clip_wl_own_selection(Clipboard_T *cbd);

54 +

static void clip_wl_lose_selection(Clipboard_T *cbd);

55 +

static void clip_wl_set_selection(Clipboard_T *cbd);

52 56

static void clip_wl_selection_cancelled(wayland_selection_T selection);

53 57 54 58

#if defined(USE_SYSTEM) && defined(PROTO)

@@ -2336,11 +2340,10 @@ adjust_clip_reg(int *rp)

2336 2340

static void

2337 2341

clip_wl_receive_data(Clipboard_T *cbd, const char *mime_type, int fd)

2338 2342

{

2339 -

char_u *start, *buf, *tmp, *final, *enc;

2340 -

int motion_type = MAUTO;

2341 -

ssize_t r = 0;

2342 -

size_t total = 0, max_total = 4096; // Initial buffer size, 4096

2343 -

// bytes seems reasonable.

2343 +

char_u *start, *final, *enc;

2344 +

garray_T buf;

2345 +

int motion_type = MAUTO;

2346 +

ssize_t r = 0;

2344 2347

#ifndef HAVE_SELECT

2345 2348

struct pollfd pfd

2346 2349

@@ -2358,17 +2361,21 @@ clip_wl_receive_data(Clipboard_T *cbd, const char *mime_type, int fd)

2358 2361

if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) == -1)

2359 2362

return;

2360 2363 2361 -

if ((buf = alloc_clear(max_total)) == NULL)

2364 +

ga_init2(&buf, 1, 4096);

2365 + 2366 +

// 4096 bytes seems reasonable for initial buffer size

2367 +

if (ga_grow(&buf, 4096) == FAIL)

2362 2368

return;

2363 -

start = buf;

2369 + 2370 +

start = buf.ga_data;

2364 2371 2365 2372

// Only poll before reading when we first start, then we do non-blocking

2366 2373

// reads and check for EAGAIN or EINTR to signal to poll again.

2367 2374

goto poll_data;

2368 2375 2369 2376

while (errno = 0, TRUE)

2370 2377

{

2371 -

r = read(fd, start, max_total - 1 - total);

2378 +

r = read(fd, start, buf.ga_maxlen - 1 - buf.ga_len);

2372 2379 2373 2380

if (r == 0)

2374 2381

break;

@@ -2391,44 +2398,39 @@ clip_wl_receive_data(Clipboard_T *cbd, const char *mime_type, int fd)

2391 2398

}

2392 2399 2393 2400

start += r;

2394 -

total += (size_t)r;

2401 +

buf.ga_len += r;

2395 2402 2396 2403

// Realloc if we are at the end of the buffer

2397 -

if (total >= max_total - 1)

2404 +

if (buf.ga_len >= buf.ga_maxlen - 1)

2398 2405

{

2399 -

tmp = vim_realloc(buf, max_total * 2);

2400 -

if (tmp == NULL)

2406 +

if (ga_grow(&buf, 8192) == FAIL)

2401 2407

break;

2402 -

max_total *= 2; // Double buffer size each time

2403 -

buf = tmp;

2404 -

start = buf + total;

2405 -

// Zero out the newly allocated memory part

2406 -

vim_memset(buf + total, 0, max_total - total);

2408 +

start = buf.ga_data + buf.ga_len;

2407 2409

}

2408 2410

}

2409 2411 2410 -

if (total == 0)

2412 +

if (buf.ga_len == 0)

2411 2413

{

2412 2414

clip_free_selection(cbd); // Nothing received, clear register

2413 -

vim_free(buf);

2415 +

ga_clear(&buf);

2414 2416

return;

2415 2417

}

2416 2418 2417 -

final = buf;

2419 +

final = buf.ga_data;

2418 2420 2419 -

if (STRCMP(mime_type, VIM_ATOM_NAME) == 0 && total >= 2)

2421 +

if (STRCMP(mime_type, VIM_ATOM_NAME) == 0 && buf.ga_len >= 2)

2420 2422

{

2421 2423

motion_type = *final++;;

2422 -

total--;

2424 +

buf.ga_len--;

2423 2425

}

2424 -

else if (STRCMP(mime_type, VIMENC_ATOM_NAME) == 0 && total >= 3)

2426 +

else if (STRCMP(mime_type, VIMENC_ATOM_NAME) == 0 && buf.ga_len >= 3)

2425 2427

{

2426 -

vimconv_T conv;

2427 -

int convlen;

2428 +

vimconv_T conv;

2429 +

int convlen;

2428 2430 2429 2431

// first byte is motion type

2430 2432

motion_type = *final++;

2431 -

total--;

2433 +

buf.ga_len--;

2432 2434 2433 2435

// Get encoding of selection

2434 2436

enc = final;

@@ -2437,30 +2439,32 @@ clip_wl_receive_data(Clipboard_T *cbd, const char *mime_type, int fd)

2437 2439

final += STRLEN(final) + 1;

2438 2440 2439 2441

// Subtract pointers to get length of encoding;

2440 -

total -= final - enc;

2442 +

buf.ga_len -= final - enc;

2441 2443 2442 2444

conv.vc_type = CONV_NONE;

2443 2445

convert_setup(&conv, enc, p_enc);

2444 2446

if (conv.vc_type != CONV_NONE)

2445 2447

{

2446 -

convlen = total;

2448 +

char_u *tmp;

2449 + 2450 +

convlen = buf.ga_len;

2447 2451

tmp = string_convert(&conv, final, &convlen);

2448 -

total = convlen;

2452 +

buf.ga_len = convlen;

2449 2453

if (tmp != NULL)

2450 2454

final = tmp;

2451 2455

convert_setup(&conv, NULL, NULL);

2452 2456

}

2453 2457

}

2454 2458 2455 -

clip_yank_selection(motion_type, final, (long)total, cbd);

2456 -

vim_free(buf);

2459 +

clip_yank_selection(motion_type, final, (long)buf.ga_len, cbd);

2460 +

ga_clear(&buf);

2457 2461

}

2458 2462 2459 2463

/*

2460 2464

* Get the current selection and fill the respective register for cbd with the

2461 2465

* data.

2462 2466

*/

2463 -

void

2467 +

static void

2464 2468

clip_wl_request_selection(Clipboard_T *cbd)

2465 2469

{

2466 2470

wayland_selection_T selection;

@@ -2646,7 +2650,7 @@ clip_wl_selection_cancelled(wayland_selection_T selection)

2646 2650

* other Wayland clients so they can receive data from us. Returns OK on success

2647 2651

* and FAIL on failure.

2648 2652

*/

2649 -

int

2653 +

static int

2650 2654

clip_wl_own_selection(Clipboard_T *cbd)

2651 2655

{

2652 2656

wayland_selection_T selection;

@@ -2670,7 +2674,7 @@ clip_wl_own_selection(Clipboard_T *cbd)

2670 2674

* Disown the selection that cbd corresponds to. Note that the the cancelled

2671 2675

* event is not sent when the data source is destroyed.

2672 2676

*/

2673 -

void

2677 +

static void

2674 2678

clip_wl_lose_selection(Clipboard_T *cbd)

2675 2679

{

2676 2680

if (cbd == &clip_plus)

@@ -2685,7 +2689,7 @@ clip_wl_lose_selection(Clipboard_T *cbd)

2685 2689

* Send the current selection to the clipboard. Do nothing for Wayland because

2686 2690

* we will fill in the selection only when requested by another client.

2687 2691

*/

2688 -

void

2692 +

static void

2689 2693

clip_wl_set_selection(Clipboard_T *cbd UNUSED)

2690 2694

{

2691 2695

}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4