avoid-multiple-calls-to-memcpy-genam.patch

application/octet-stream

Filename: avoid-multiple-calls-to-memcpy-genam.patch
Type: application/octet-stream
Part: 0
Message: Avoid multiple calls to memcpy (src/backend/access/index/genam.c)

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/backend/access/index/genam.c 4 4
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c
index 5e89b86a62..affaed2c48 100644
--- a/src/backend/access/index/genam.c
+++ b/src/backend/access/index/genam.c
@@ -435,13 +435,13 @@ systable_beginscan(Relation heapRelation,
 
 		idxkey = palloc_array(ScanKeyData, nkeys);
 
+		memcpy(idxkey, key, nkeys * sizeof(ScanKeyData));
+
 		/* Convert attribute numbers to be index column numbers. */
 		for (i = 0; i < nkeys; i++)
 		{
 			int			j;
 
-			memcpy(&idxkey[i], &key[i], sizeof(ScanKeyData));
-
 			for (j = 0; j < IndexRelationGetNumberOfAttributes(irel); j++)
 			{
 				if (key[i].sk_attno == irel->rd_index->indkey.values[j])
@@ -688,13 +688,13 @@ systable_beginscan_ordered(Relation heapRelation,
 
 	idxkey = palloc_array(ScanKeyData, nkeys);
 
+	memcpy(idxkey, key, nkeys * sizeof(ScanKeyData));
+
 	/* Convert attribute numbers to be index column numbers. */
 	for (i = 0; i < nkeys; i++)
 	{
 		int			j;
 
-		memcpy(&idxkey[i], &key[i], sizeof(ScanKeyData));
-
 		for (j = 0; j < IndexRelationGetNumberOfAttributes(indexRelation); j++)
 		{
 			if (key[i].sk_attno == indexRelation->rd_index->indkey.values[j])