* [PATCH] coccinelle: merge twelve rules from object_id.cocci
@ 2019-11-14 12:10 Markus Elfring
2019-11-16 5:59 ` brian m. carlson
0 siblings, 1 reply; 2+ messages in thread
From: Markus Elfring @ 2019-11-14 12:10 UTC (permalink / raw)
To: git; +Cc: Brian M. Carlson, Gábor Szeder, Jeff King, René Scharfe
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 14 Nov 2019 12:48:27 +0100
This script contained transformation rules for the semantic patch language
which used similar code.
Combine these rules by using five SmPL disjunctions so that the run time
characteristics can be nicer because of common usage of a few metavariables.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
contrib/coccinelle/object_id.cocci | 89 +++++++++++++-----------------
1 file changed, 37 insertions(+), 52 deletions(-)
diff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci
index 3e536a9834..5e8fc4659a 100644
--- a/contrib/coccinelle/object_id.cocci
+++ b/contrib/coccinelle/object_id.cocci
@@ -1,20 +1,33 @@
@@
-struct object_id OID;
-@@
-- is_null_sha1(OID.hash)
-+ is_null_oid(&OID)
-
-@@
+expression E;
+struct object_id OID, OID2;
struct object_id *OIDPTR;
@@
-- is_null_sha1(OIDPTR->hash)
-+ is_null_oid(OIDPTR)
-
-@@
-struct object_id OID;
-@@
+(
+- is_null_sha1
++ is_null_oid
+ (
+(
+- OID.hash
++ &OID
+|
+ OIDPTR
+- ->hash
+)
+ )
+|
- sha1_to_hex(OID.hash)
+ oid_to_hex(&OID)
+|
+- sha1_to_hex_r(E, OID.hash)
++ oid_to_hex_r(E, &OID)
+|
+- hashclr(OID.hash)
++ oidclr(&OID)
+|
+- hashcmp(OID.hash, OID2.hash)
++ oidcmp(&OID, &OID2)
+)
@@
identifier f != oid_to_hex;
@@ -25,13 +38,6 @@ struct object_id *OIDPTR;
+ oid_to_hex(OIDPTR)
...>}
-@@
-expression E;
-struct object_id OID;
-@@
-- sha1_to_hex_r(E, OID.hash)
-+ oid_to_hex_r(E, &OID)
-
@@
identifier f != oid_to_hex_r;
expression E;
@@ -42,12 +48,6 @@ struct object_id *OIDPTR;
+ oid_to_hex_r(E, OIDPTR)
...>}
-@@
-struct object_id OID;
-@@
-- hashclr(OID.hash)
-+ oidclr(&OID)
-
@@
identifier f != oidclr;
struct object_id *OIDPTR;
@@ -57,12 +57,6 @@ struct object_id *OIDPTR;
+ oidclr(OIDPTR)
...>}
-@@
-struct object_id OID1, OID2;
-@@
-- hashcmp(OID1.hash, OID2.hash)
-+ oidcmp(&OID1, &OID2)
-
@@
identifier f != oidcmp;
struct object_id *OIDPTR1, OIDPTR2;
@@ -76,44 +70,35 @@ struct object_id *OIDPTR1, OIDPTR2;
struct object_id *OIDPTR;
struct object_id OID;
@@
+(
- hashcmp(OIDPTR->hash, OID.hash)
+ oidcmp(OIDPTR, &OID)
-
-@@
-struct object_id *OIDPTR;
-struct object_id OID;
-@@
+|
- hashcmp(OID.hash, OIDPTR->hash)
+ oidcmp(&OID, OIDPTR)
+)
@@
-struct object_id *OIDPTR1;
-struct object_id *OIDPTR2;
+struct object_id * OIDPTR1, OIDPTR2;
@@
+(
- oidcmp(OIDPTR1, OIDPTR2) == 0
+ oideq(OIDPTR1, OIDPTR2)
-
-@@
-identifier f != hasheq;
-expression E1, E2;
-@@
- f(...) {<...
-- hashcmp(E1, E2) == 0
-+ hasheq(E1, E2)
- ...>}
-
-@@
-struct object_id *OIDPTR1;
-struct object_id *OIDPTR2;
-@@
+|
- oidcmp(OIDPTR1, OIDPTR2) != 0
+ !oideq(OIDPTR1, OIDPTR2)
+)
@@
identifier f != hasheq;
expression E1, E2;
@@
f(...) {<...
+(
+- hashcmp(E1, E2) == 0
++ hasheq(E1, E2)
+|
- hashcmp(E1, E2) != 0
+ !hasheq(E1, E2)
+)
...>}
--
2.24.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] coccinelle: merge twelve rules from object_id.cocci
2019-11-14 12:10 [PATCH] coccinelle: merge twelve rules from object_id.cocci Markus Elfring
@ 2019-11-16 5:59 ` brian m. carlson
0 siblings, 0 replies; 2+ messages in thread
From: brian m. carlson @ 2019-11-16 5:59 UTC (permalink / raw)
To: Markus Elfring; +Cc: git, Gábor Szeder, Jeff King, René Scharfe
[-- Attachment #1: Type: text/plain, Size: 651 bytes --]
On 2019-11-14 at 12:10:26, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 14 Nov 2019 12:48:27 +0100
>
> This script contained transformation rules for the semantic patch language
> which used similar code.
> Combine these rules by using five SmPL disjunctions so that the run time
> characteristics can be nicer because of common usage of a few metavariables.
This seems like a nice improvement. It's probably quite obvious, but my
skills with Coccinelle are rather limited, so I appreciate you cleaning
this up.
--
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-16 5:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-14 12:10 [PATCH] coccinelle: merge twelve rules from object_id.cocci Markus Elfring
2019-11-16 5:59 ` brian m. carlson
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).