[hackers] [surf][PATCH] define one atom per line; use XInternAtoms(3)

From: seninha <lucas_AT_seninha.org>
Date: Tue, 4 Oct 2022 22:42:15 -0300

This commit changes two things for Atoms.

First it changes the Atoms enum from a single line to one Atom per line.
This makes it easy for applying patchs that add more Atoms to the list.
With a single line, two patches adding atoms will conflict when changing
the same line. With one line per atom, such patches will not conflict.

Second, it replaces XInternAtom(3) with XInternAtoms(3). This change
makes it easy to write a patch adding a new atom (it's just necessary to
add an entry on the `atomnames` array). It is also faster than multiple
calls to XInternAtom(3), as said in the manual:

> Calling this function is equivalent to calling XInternAtom for each of
> the names in turn with the specified value of only_if_exists, but this
> function minimizes the number of round-trip protocol exchanges between
> the client and the X server.
---
 surf.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/surf.c b/surf.c
index 474c01b..57ae7c0 100644
--- a/surf.c
+++ b/surf.c
_AT_@ -37,7 +37,13 @@
 #define LENGTH(x)               (sizeof(x) / sizeof(x[0]))
 #define CLEANMASK(mask)         (mask & (MODKEY|GDK_SHIFT_MASK))
 
-enum { AtomFind, AtomGo, AtomUri, AtomUTF8, AtomLast };
+enum {
+	AtomFind,
+	AtomGo,
+	AtomUri,
+	AtomUTF8,
+	AtomLast
+};
 
 enum {
 	OnDoc   = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
_AT_@ -259,6 +265,13 @@ static int modparams[ParameterLast];
 static int spair[2];
 char *argv0;
 
+static char *atomnames[AtomLast] = {
+	[AtomFind] = "_SURF_FIND",
+	[AtomGo] = "_SURF_GO",
+	[AtomUri] = "_SURF_URI",
+	[AtomUTF8] = "UTF8_STRING",
+};
+
 static ParamName loadtransient[] = {
 	Certificate,
 	CookiePolicies,
_AT_@ -340,10 +353,7 @@ setup(void)
 		die("Can't open default display");
 
 	/* atoms */
-	atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
-	atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
-	atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
-	atoms[AtomUTF8] = XInternAtom(dpy, "UTF8_STRING", False);
+	XInternAtoms(dpy, atomnames, AtomLast, False, atoms);
 
 	gtk_init(NULL, NULL);
 
-- 
2.37.3
Received on Wed Oct 05 2022 - 03:42:15 CEST

This archive was generated by hypermail 2.3.0 : Wed Oct 05 2022 - 03:48:36 CEST