From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.devel Subject: Re: Universal functions to manage multiple window caches. Date: Wed, 17 Apr 2019 20:17:39 -0700 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="262462"; mail-complaints-to="usenet@blaine.gmane.org" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Apr 18 05:17:55 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGxYg-001670-CW for ged-emacs-devel@m.gmane.org; Thu, 18 Apr 2019 05:17:55 +0200 Original-Received: from localhost ([127.0.0.1]:34766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGxYe-0001uS-Ru for ged-emacs-devel@m.gmane.org; Wed, 17 Apr 2019 23:17:52 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:51411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGxYX-0001u8-Ox for emacs-devel@gnu.org; Wed, 17 Apr 2019 23:17:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGxYU-0006Xr-J2 for emacs-devel@gnu.org; Wed, 17 Apr 2019 23:17:45 -0400 Original-Received: from gateway23.websitewelcome.com ([192.185.50.129]:24129) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hGxYU-0006Wy-5m for emacs-devel@gnu.org; Wed, 17 Apr 2019 23:17:42 -0400 Original-Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway23.websitewelcome.com (Postfix) with ESMTP id A03E08A85 for ; Wed, 17 Apr 2019 22:17:40 -0500 (CDT) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id GxYShqlLoYTGMGxYShy1Nj; Wed, 17 Apr 2019 22:17:40 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com ; s=default; h=Content-Type:MIME-Version:Subject:To:From:Message-ID:Date: Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=sxIsLQQoKBCh9bC7eTSDI/cKLWbOcomhHbJS1tJz20I=; b=PPnkaKlsFw7R/3cvQokpQkvwIZ SgFmRQWT5+g/VM8L7AE1ZLGzk2qK+zpgpjjCF12JCUrWTo1BqpzY9f71C1d5MD/D1KnmYAEiJ8V06 blmhHdfBxMNIhNruIygtvM8/TMgN+O2tHZTOL+7v93YmEyXnWrGpfrpk4gtA1dURBkaJXYTGZpNXo iTaQZBlf92jf8jlQf07AxCykFM8sTF+52ph6HrdIp1rYC5I5NgQNLRUFBf9XSjTqN7dD6jhxUkdeT w4mtoQtufIQ+WxzhBqbA3m2KOWkgnLHwOwLD+wsdS9eP8o3ckTlcoI0JxtuKJ/FRQoqOXowQcTas3 qhPvzetg==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:53566 helo=server.local) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.91) (envelope-from ) id 1hGxYR-0020HG-Pd for emacs-devel@gnu.org; Wed, 17 Apr 2019 22:17:39 -0500 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3053.hostgator.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-BWhitelist: no X-Source-IP: 45.48.239.195 X-Source-L: No X-Exim-ID: 1hGxYR-0020HG-Pd X-Source-Sender: cpe-45-48-239-195.socal.res.rr.com (server.local) [45.48.239.195]:53566 X-Source-Auth: lawlist X-Email-Count: 1 X-Source-Cap: bGF3bGlzdDtsYXdsaXN0O2dhdG9yMzA1My5ob3N0Z2F0b3IuY29t X-Local-Domain: yes X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 192.185.50.129 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:235611 Archived-At: The following two functions for reset / populate are working; however, several sections of code are essentially repeated (for lack of figuring out a more concise approach). Although not critical to the overall design, a more efficient way to write these up would be greatly appreciated. void mc_reset_cache (struct window *w, enum type_of_cache cache_type) { switch (cache_type) { case NO_CACHE: { return; } case MC_TEMP_CACHE: { if (w->temp_nelts > 1) { /* Decrease the size of the array to a bare minimum. */ xnrealloc (w->temp_elts, 1, sizeof *w->temp_elts); w->temp_nelts = 0; w->temp_elts_allocated = 1; } else { /* Set all _used_ elements of the array to zero. elts_allocated remain the same. */ memset (w->temp_elts, 0, w->temp_nelts * (sizeof *w->temp_elts)); w->temp_nelts = 0; } break; } case MC_CACHE: { if (BUFFERP (w->contents) && NILP (BVAR (XBUFFER (w->contents), mc_conf)) && w->mc_nelts > 1) { /* Decrease the size of the array to a bare minimum. */ xnrealloc (w->mc_elts, 1, sizeof *w->mc_elts); w->mc_nelts = 0; w->mc_elts_allocated = 1; } else if (BUFFERP (w->contents) && !NILP (BVAR (XBUFFER (w->contents), mc_conf))) { /* Set all _used_ elements of the array to zero. elts_allocated remain the same. */ memset (w->mc_elts, 0, w->mc_nelts * (sizeof *w->mc_elts)); w->mc_nelts = 0; } break; } case CH_CACHE: { if (BUFFERP (w->contents) && NILP (BVAR (XBUFFER (w->contents), crosshairs)) && w->ch_nelts > 1) { /* Decrease the size of the array to a bare minimum. */ xnrealloc (w->ch_elts, 1, sizeof *w->ch_elts); w->ch_nelts = 0; w->ch_elts_allocated = 1; } else if (BUFFERP (w->contents) && !NILP (BVAR (XBUFFER (w->contents), crosshairs))) { /* Set all _used_ elements of the array to zero. elts_allocated remain the same. */ memset (w->ch_elts, 0, w->ch_nelts * (sizeof *w->ch_elts)); w->ch_nelts = 0; } break; } case FC_CACHE: { if (BUFFERP (w->contents) && NILP (BVAR (XBUFFER (w->contents), fc_visible)) && w->fc_nelts > 1) { /* Decrease the size of the array to a bare minimum. */ xnrealloc (w->fc_elts, 1, sizeof *w->fc_elts); w->fc_nelts = 0; w->fc_elts_allocated = 1; } else if (BUFFERP (w->contents) && !NILP (BVAR (XBUFFER (w->contents), fc_visible))) { /* Set all _used_ elements of the array to zero. elts_allocated remain the same. */ memset (w->fc_elts, 0, w->fc_nelts * (sizeof *w->fc_elts)); w->fc_nelts = 0; } break; } } } static void mc_helper (struct window *w, struct glyph_matrix *matrix, struct glyph_row *row, struct glyph *glyph, int x, int fx, int y, int fy, int hpos, int vpos, int wd, int h, enum text_cursor_kinds cursor_type, int cursor_width, struct RGB foreground, struct RGB background, bool active_p, enum mc_flavor glyph_flavor, bool draw_p, enum type_of_cache cache_type) { . . . struct multiple_cursors_cache *foo_elts; ptrdiff_t *foo_elts_allocated; int *foo_nelts; switch (cache_type) { case NO_CACHE: { return; } case MC_TEMP_CACHE: { ++w->temp_nelts; if (w->temp_elts_allocated < w->temp_nelts) { int old_alloc = w->temp_elts_allocated; int new_elts = w->temp_nelts - w->temp_elts_allocated; w->temp_elts = xpalloc (w->temp_elts, &w->temp_elts_allocated, new_elts, INT_MAX, sizeof *w->temp_elts); memset (w->temp_elts + old_alloc, 0, (w->temp_elts_allocated - old_alloc) * sizeof *w->temp_elts); } foo_elts = w->temp_elts; foo_elts_allocated = &w->temp_elts_allocated; foo_nelts = &w->temp_nelts; break; } case MC_CACHE: { ++w->mc_nelts; if (w->mc_elts_allocated < w->mc_nelts) { int old_alloc = w->mc_elts_allocated; int new_elts = w->mc_nelts - w->mc_elts_allocated; w->mc_elts = xpalloc (w->mc_elts, &w->mc_elts_allocated, new_elts, INT_MAX, sizeof *w->mc_elts); memset (w->mc_elts + old_alloc, 0, (w->mc_elts_allocated - old_alloc) * sizeof *w->mc_elts); } foo_elts = w->mc_elts; foo_elts_allocated = &w->mc_elts_allocated; foo_nelts = &w->mc_nelts; break; } case CH_CACHE: { ++w->ch_nelts; if (w->ch_elts_allocated < w->ch_nelts) { int old_alloc = w->ch_elts_allocated; int new_elts = w->ch_nelts - w->ch_elts_allocated; w->ch_elts = xpalloc (w->ch_elts, &w->ch_elts_allocated, new_elts, INT_MAX, sizeof *w->ch_elts); memset (w->ch_elts + old_alloc, 0, (w->ch_elts_allocated - old_alloc) * sizeof *w->ch_elts); } foo_elts = w->ch_elts; foo_elts_allocated = &w->ch_elts_allocated; foo_nelts = &w->ch_nelts; break; } case FC_CACHE: { ++w->fc_nelts; if (w->fc_elts_allocated < w->fc_nelts) { int old_alloc = w->fc_elts_allocated; int new_elts = w->fc_nelts - w->fc_elts_allocated; w->fc_elts = xpalloc (w->fc_elts, &w->fc_elts_allocated, new_elts, INT_MAX, sizeof *w->fc_elts); memset (w->fc_elts + old_alloc, 0, (w->fc_elts_allocated - old_alloc) * sizeof *w->fc_elts); } foo_elts = w->fc_elts; foo_elts_allocated = &w->fc_elts_allocated; foo_nelts = &w->fc_nelts; break; } } int nth = *foo_nelts - 1; foo_elts[nth].x = x; foo_elts[nth].fx = fx; foo_elts[nth].y = y; foo_elts[nth].fy = fy; foo_elts[nth].hpos = hpos; foo_elts[nth].vpos = vpos; foo_elts[nth].wd = wd; foo_elts[nth].h = h; foo_elts[nth].cursor_type = cursor_type; foo_elts[nth].cursor_width = cursor_width; foo_elts[nth].foreground.red = foreground.red; foo_elts[nth].foreground.green = foreground.green; foo_elts[nth].foreground.blue = foreground.blue; foo_elts[nth].background.red = background.red; foo_elts[nth].background.green = background.green; foo_elts[nth].background.blue = background.blue; foo_elts[nth].active_p = active_p; foo_elts[nth].glyph_flavor = glyph_flavor; foo_elts[nth].enabled_p = true; }