@@ -263,6 +263,7 @@ bms_intersect(const Bitmapset *a, const Bitmapset *b)
263
263
/* Handle cases where either input is NULL */
264
264
if (a == NULL || b == NULL )
265
265
return NULL ;
266
+
266
267
/* Identify shorter and longer input; copy the shorter one */
267
268
if (a -> nwords <= b -> nwords )
268
269
{
@@ -798,8 +799,15 @@ bms_add_member(Bitmapset *a, int x)
798
799
{
799
800
int oldnwords = a -> nwords ;
800
801
int i ;
802
+ #ifdef REALLOCATE_BITMAPSETS
803
+ Bitmapset * tmp = a ;
801
804
805
+ a = (Bitmapset * ) palloc (BITMAPSET_SIZE (wordnum + 1 ));
806
+ memcpy (a , tmp , BITMAPSET_SIZE (tmp -> nwords ));
807
+ pfree (tmp );
808
+ #else
802
809
a = (Bitmapset * ) repalloc (a , BITMAPSET_SIZE (wordnum + 1 ));
810
+ #endif
803
811
a -> nwords = wordnum + 1 ;
804
812
/* zero out the enlarged portion */
805
813
i = oldnwords ;
@@ -808,6 +816,16 @@ bms_add_member(Bitmapset *a, int x)
808
816
a -> words [i ] = 0 ;
809
817
} while (++ i < a -> nwords );
810
818
}
819
+ #ifdef REALLOCATE_BITMAPSETS
820
+ else
821
+ {
822
+ Bitmapset * tmp = a ;
823
+
824
+ a = (Bitmapset * ) palloc (BITMAPSET_SIZE (tmp -> nwords ));
825
+ memcpy (a , tmp , BITMAPSET_SIZE (tmp -> nwords ));
826
+ pfree (tmp );
827
+ }
828
+ #endif
811
829
812
830
a -> words [wordnum ] |= ((bitmapword ) 1 << bitnum );
813
831
return a ;
@@ -825,6 +843,9 @@ bms_del_member(Bitmapset *a, int x)
825
843
{
826
844
int wordnum ,
827
845
bitnum ;
846
+ #ifdef REALLOCATE_BITMAPSETS
847
+ Bitmapset * tmp = a ;
848
+ #endif
828
849
829
850
if (x < 0 )
830
851
elog (ERROR , "negative bitmapset member not allowed" );
@@ -836,6 +857,12 @@ bms_del_member(Bitmapset *a, int x)
836
857
wordnum = WORDNUM (x );
837
858
bitnum = BITNUM (x );
838
859
860
+ #ifdef REALLOCATE_BITMAPSETS
861
+ a = (Bitmapset * ) palloc (BITMAPSET_SIZE (tmp -> nwords ));
862
+ memcpy (a , tmp , BITMAPSET_SIZE (tmp -> nwords ));
863
+ pfree (tmp );
864
+ #endif
865
+
839
866
/* member can't exist. Return 'a' unmodified */
840
867
if (unlikely (wordnum >= a -> nwords ))
841
868
return a ;
@@ -889,6 +916,13 @@ bms_add_members(Bitmapset *a, const Bitmapset *b)
889
916
}
890
917
else
891
918
{
919
+ #ifdef REALLOCATE_BITMAPSETS
920
+ Bitmapset * tmp = a ;
921
+
922
+ a = (Bitmapset * ) palloc (BITMAPSET_SIZE (tmp -> nwords ));
923
+ memcpy (a , tmp , BITMAPSET_SIZE (tmp -> nwords ));
924
+ pfree (tmp );
925
+ #endif
892
926
result = a ;
893
927
other = b ;
894
928
}
@@ -941,9 +975,16 @@ bms_add_range(Bitmapset *a, int lower, int upper)
941
975
{
942
976
int oldnwords = a -> nwords ;
943
977
int i ;
978
+ #ifdef REALLOCATE_BITMAPSETS
979
+ Bitmapset * tmp = a ;
944
980
981
+ a = (Bitmapset * ) palloc (BITMAPSET_SIZE (uwordnum + 1 ));
982
+ memcpy (a , tmp , BITMAPSET_SIZE (tmp -> nwords ));
983
+ pfree (tmp );
984
+ #else
945
985
/* ensure we have enough words to store the upper bit */
946
986
a = (Bitmapset * ) repalloc (a , BITMAPSET_SIZE (uwordnum + 1 ));
987
+ #endif
947
988
a -> nwords = uwordnum + 1 ;
948
989
/* zero out the enlarged portion */
949
990
i = oldnwords ;
@@ -992,6 +1033,12 @@ bms_int_members(Bitmapset *a, const Bitmapset *b)
992
1033
int lastnonzero ;
993
1034
int shortlen ;
994
1035
int i ;
1036
+ #ifdef REALLOCATE_BITMAPSETS
1037
+ Bitmapset * tmp = a ;
1038
+ #endif
1039
+
1040
+ Assert (a == NULL || IsA (a , Bitmapset ));
1041
+ Assert (b == NULL || IsA (b , Bitmapset ));
995
1042
996
1043
Assert (a == NULL || IsA (a , Bitmapset ));
997
1044
Assert (b == NULL || IsA (b , Bitmapset ));
@@ -1004,6 +1051,13 @@ bms_int_members(Bitmapset *a, const Bitmapset *b)
1004
1051
pfree (a );
1005
1052
return NULL ;
1006
1053
}
1054
+
1055
+ #ifdef REALLOCATE_BITMAPSETS
1056
+ a = (Bitmapset * ) palloc (BITMAPSET_SIZE (tmp -> nwords ));
1057
+ memcpy (a , tmp , BITMAPSET_SIZE (tmp -> nwords ));
1058
+ pfree (tmp );
1059
+ #endif
1060
+
1007
1061
/* Intersect b into a; we need never copy */
1008
1062
shortlen = Min (a -> nwords , b -> nwords );
1009
1063
lastnonzero = -1 ;
@@ -1035,6 +1089,9 @@ Bitmapset *
1035
1089
bms_del_members (Bitmapset * a , const Bitmapset * b )
1036
1090
{
1037
1091
int i ;
1092
+ #ifdef REALLOCATE_BITMAPSETS
1093
+ Bitmapset * tmp = a ;
1094
+ #endif
1038
1095
1039
1096
Assert (a == NULL || (IsA (a , Bitmapset ) && a -> words [a -> nwords - 1 ] != 0 ));
1040
1097
Assert (b == NULL || (IsA (b , Bitmapset ) && b -> words [b -> nwords - 1 ] != 0 ));
@@ -1044,6 +1101,13 @@ bms_del_members(Bitmapset *a, const Bitmapset *b)
1044
1101
return NULL ;
1045
1102
if (b == NULL )
1046
1103
return a ;
1104
+
1105
+ #ifdef REALLOCATE_BITMAPSETS
1106
+ a = (Bitmapset * ) palloc (BITMAPSET_SIZE (tmp -> nwords ));
1107
+ memcpy (a , tmp , BITMAPSET_SIZE (tmp -> nwords ));
1108
+ pfree (tmp );
1109
+ #endif
1110
+
1047
1111
/* Remove b's bits from a; we need never copy */
1048
1112
if (a -> nwords > b -> nwords )
1049
1113
{
@@ -1096,6 +1160,12 @@ bms_join(Bitmapset *a, Bitmapset *b)
1096
1160
Bitmapset * other ;
1097
1161
int otherlen ;
1098
1162
int i ;
1163
+ #ifdef REALLOCATE_BITMAPSETS
1164
+ Bitmapset * tmp = a ;
1165
+ #endif
1166
+
1167
+ Assert (a == NULL || IsA (a , Bitmapset ));
1168
+ Assert (b == NULL || IsA (b , Bitmapset ));
1099
1169
1100
1170
Assert (a == NULL || IsA (a , Bitmapset ));
1101
1171
Assert (b == NULL || IsA (b , Bitmapset ));
@@ -1105,6 +1175,13 @@ bms_join(Bitmapset *a, Bitmapset *b)
1105
1175
return b ;
1106
1176
if (b == NULL )
1107
1177
return a ;
1178
+
1179
+ #ifdef REALLOCATE_BITMAPSETS
1180
+ a = (Bitmapset * ) palloc (BITMAPSET_SIZE (tmp -> nwords ));
1181
+ memcpy (a , tmp , BITMAPSET_SIZE (tmp -> nwords ));
1182
+ pfree (tmp );
1183
+ #endif
1184
+
1108
1185
/* Identify shorter and longer input; use longer one as result */
1109
1186
if (a -> nwords < b -> nwords )
1110
1187
{
0 commit comments