Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d50183c

Browse files
committed
Inline the easy cases in MakeExpandedObjectReadOnly().
This attempts to buy back some of whatever performance we lost from fixing bug #14174 by inlining the initial checks in MakeExpandedObjectReadOnly() into the callers. We can do that in a macro without creating multiple- evaluation hazards, so it's pretty much free notationally; and the amount of code added to callers should be minimal as well. (Testing a value can't take many more instructions than passing it to a subroutine.) Might as well inline DatumIsReadWriteExpandedObject() while we're at it. This is an ABI break for callers, so it doesn't seem safe to put into 9.5, but I see no reason not to do it in HEAD.
1 parent 9eaf5be commit d50183c

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

src/backend/utils/adt/expandeddatum.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,36 +84,18 @@ EOH_flatten_into(ExpandedObjectHeader *eohptr,
8484
(*eohptr->eoh_methods->flatten_into) (eohptr, result, allocated_size);
8585
}
8686

87-
/*
88-
* Does the Datum represent a writable expanded object?
89-
*/
90-
bool
91-
DatumIsReadWriteExpandedObject(Datum d, bool isnull, int16 typlen)
92-
{
93-
/* Reject if it's NULL or not a varlena type */
94-
if (isnull || typlen != -1)
95-
return false;
96-
97-
/* Reject if not a read-write expanded-object pointer */
98-
if (!VARATT_IS_EXTERNAL_EXPANDED_RW(DatumGetPointer(d)))
99-
return false;
100-
101-
return true;
102-
}
103-
10487
/*
10588
* If the Datum represents a R/W expanded object, change it to R/O.
10689
* Otherwise return the original Datum.
90+
*
91+
* Caller must ensure that the datum is a non-null varlena value. Typically
92+
* this is invoked via MakeExpandedObjectReadOnly(), which checks that.
10793
*/
10894
Datum
109-
MakeExpandedObjectReadOnly(Datum d, bool isnull, int16 typlen)
95+
MakeExpandedObjectReadOnlyInternal(Datum d)
11096
{
11197
ExpandedObjectHeader *eohptr;
11298

113-
/* Nothing to do if it's NULL or not a varlena type */
114-
if (isnull || typlen != -1)
115-
return d;
116-
11799
/* Nothing to do if not a read-write expanded-object pointer */
118100
if (!VARATT_IS_EXTERNAL_EXPANDED_RW(DatumGetPointer(d)))
119101
return d;

src/include/utils/expandeddatum.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,23 @@ struct ExpandedObjectHeader
136136
#define EOHPGetRWDatum(eohptr) PointerGetDatum((eohptr)->eoh_rw_ptr)
137137
#define EOHPGetRODatum(eohptr) PointerGetDatum((eohptr)->eoh_ro_ptr)
138138

139+
/* Does the Datum represent a writable expanded object? */
140+
#define DatumIsReadWriteExpandedObject(d, isnull, typlen) \
141+
(((isnull) || (typlen) != -1) ? false : \
142+
VARATT_IS_EXTERNAL_EXPANDED_RW(DatumGetPointer(d)))
143+
144+
#define MakeExpandedObjectReadOnly(d, isnull, typlen) \
145+
(((isnull) || (typlen) != -1) ? (d) : \
146+
MakeExpandedObjectReadOnlyInternal(d))
147+
139148
extern ExpandedObjectHeader *DatumGetEOHP(Datum d);
140149
extern void EOH_init_header(ExpandedObjectHeader *eohptr,
141150
const ExpandedObjectMethods *methods,
142151
MemoryContext obj_context);
143152
extern Size EOH_get_flat_size(ExpandedObjectHeader *eohptr);
144153
extern void EOH_flatten_into(ExpandedObjectHeader *eohptr,
145154
void *result, Size allocated_size);
146-
extern bool DatumIsReadWriteExpandedObject(Datum d, bool isnull, int16 typlen);
147-
extern Datum MakeExpandedObjectReadOnly(Datum d, bool isnull, int16 typlen);
155+
extern Datum MakeExpandedObjectReadOnlyInternal(Datum d);
148156
extern Datum TransferExpandedObject(Datum d, MemoryContext new_parent);
149157
extern void DeleteExpandedObject(Datum d);
150158

0 commit comments

Comments
 (0)