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: How to quickly compare equality of structs ... Date: Mon, 06 May 2019 11:55:18 -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="100716"; mail-complaints-to="usenet@blaine.gmane.org" To: Emacs Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 06 20:55:48 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 1hNimB-000Q3K-Q5 for ged-emacs-devel@m.gmane.org; Mon, 06 May 2019 20:55:48 +0200 Original-Received: from localhost ([127.0.0.1]:60903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNimA-0007oe-T1 for ged-emacs-devel@m.gmane.org; Mon, 06 May 2019 14:55:46 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:60399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNim3-0007oN-Gu for emacs-devel@gnu.org; Mon, 06 May 2019 14:55:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNim1-0004yt-9W for emacs-devel@gnu.org; Mon, 06 May 2019 14:55:39 -0400 Original-Received: from gateway33.websitewelcome.com ([192.185.146.82]:17230) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNilw-0004iI-Ne for emacs-devel@gnu.org; Mon, 06 May 2019 14:55:35 -0400 Original-Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway33.websitewelcome.com (Postfix) with ESMTP id B6E953BF0A for ; Mon, 6 May 2019 13:55:19 -0500 (CDT) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id Niljh3B5N90onNiljhAWrY; Mon, 06 May 2019 13:55:19 -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=kp3p7Y7lSz4BRyvBxI78Gx/b9jy2S6vqMxYjMvNBOv8=; b=SfdV/69JazfB70NP+t4BS/6e/v bRRMioH2W0gjaqmz2FblOlEUOHRKFAALz7g/Kf+jKE4Sw5nTFzvce0BajaP62qNxAZx3L8CYJlzSF Jl7i2LiqUorzDUr8GV0f5YZR4rhCoJugkAGbMYKPmau6QDEicjPEgKCnm6VW9WvH0UTflS1/0jOiv t5q0d8lXVj6yb2q/yf/TEHpCYzLWrFZC7wVifZb5/Pb6PODHRuZXU1ZaSl+QwXhP9rwoVDoA7WETZ Dm3HxgGVdAqb19lTsFbOmLov8jdE0XoB4MTm7PL2cYZ5BIiZZr+lSheObfaz8HeTAdOPPmdJM/GqR GcGBq7Lg==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:50381 helo=server.local) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.91) (envelope-from ) id 1hNili-002FDZ-SV for emacs-devel@gnu.org; Mon, 06 May 2019 13:55:18 -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: 1hNili-002FDZ-SV X-Source-Sender: cpe-45-48-239-195.socal.res.rr.com (server.local) [45.48.239.195]:50381 X-Source-Auth: lawlist X-Email-Count: 3 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.146.82 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:236206 Archived-At: I am working on feature requests 22873 (multiple fake cursors) and 17684 (crosshairs that track the cursor position). GOAL: Reduce removal of fake cursors to the bare minimum and redraw only those fake cursors that are absolutely necessary. [If done in an efficient manner, this might increase overall speed/performance and also reduce what the user sees when Emacs removes / draws fake cursors.] Fake cursors come in two varieties: (1) either they intersect a glyph; or, (2) they are floating (without any glyph intersection). Think of a vertical/horizontal line that spans the entire window-body-height/width of a visible window -- parts of the line will intersect glyphs, and other parts of the line will be floating (not intersecting anything). The floating fake cursors can only be erased with surgical precision by using cached data (screen relative coordinates, background color, dimensions of the rectangle). The cached data becomes outdated when redisplay updates w->current_matrix, so removal of fake cursors must occur prior thereto. mc_pre_scroll_clean is called _before_ redisplay updates w->current_matrix -- all fake cursors are removed and the caches are reset. This happens _before_ the text is scrolled on the glass directly by try_window_reusing_current_matrix, try_window_id, and/or scrolling_window. Fake cursors are created anew (and their data cached) immediately following calls to draw_glyphs within update_window => update_window_line => update_text_area. Part of this happens when processing w->desired_matrix (if rows are enabled), and the remainder happens using w->current_matrix. Whenever glyphs are redrawn during redisplay using w->current_matrix, fake cursors are likewise redrawn (only where needed) using cached data. Essentially, any call to draw_glyphs using w->current_matrix is a cue for fake cursors to be redrawn immediately thereafter. The cache of fake cursors is array of structs -- each fake cursors has approximately fifteen (15) elements of stored data. TENTATIVE THINKING: For each fake cursor, create a unique numeric representation of all cached elements combined; e.g., SHA1 (Secure Hash Algorithm). That unique id can be stored as an additional element for each fake cursor cached. Before the w->current_matrix (from the previous command loop) is altered, perform a dry-run to see what the new cache of fake cursors looks like. Then, compare the old and tentative new cache to determine which fake cursors must be removed and which need to be drawn. PROBLEM: If the tentative plan makes good sense, then how can I programmatically turn a combination of int, enum, double and bool into one (1) unique numeric representation such as a SHA1 (Secure Hash Algorithm)? Other ideas that are just as quick, or quicker would be greatly appreciated. The latest proof concept patch of feature requests 17684 / 22873 is now at version 19.003: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22873#137 Here is the structure of the cache of fake cursors: struct multiple_cursors_cache { ptrdiff_t allocated; ptrdiff_t used; enum type_of_cache { NO_CACHE, MC_CACHE, CH_CACHE, FC_CACHE } cache_type; struct items_in_cache { int x; int fx; int y; int fy; int hpos; int vpos; int wd; int h; enum type_of_cursor { /* NOTE: The fringe bitmap framework relies upon MC_NO_FRINGE_BITMAP HAVING A VALUE OF ZERO (0). */ MC_NO_FRINGE_BITMAP, MC_NO_CURSOR, MC_RIGHT_FRINGE_BITMAP, MC_LEFT_FRINGE_BITMAP, MC_FRAMED_BOX, MC_FILLED_BOX, MC_HOLLOW_BOX, MC_BAR, MC_HBAR } cursor_type; int cursor_width; struct RGB { double red; double green; double blue; } foreground, background; bool active_p; enum mc_flavor { NO_FLAVOR, MC_GLYPH, MC_GLYPHLESS, MC_OVERLAY_ARROW_BITMAP, MC_PILCROW, MC_HOLLOW_RECTANGLE_RIGHT_ARROW, MC_REVERSED_HOLLOW_RECTANGLE_RIGHT_ARROW, MC_HOLLOW_RECTANGLE, MC_VERTICAL_BAR_RIGHT_ARROW, MC_REVERSED_VERTICAL_BAR_RIGHT_ARROW, MC_VERTICAL_BAR, MC_REVERSED_VERTICAL_BAR, MC_VERTICAL_BAR_BACKSLASH } glyph_flavor; bool enabled_p; } *caches; };