Skip to content

Commit b041d63

Browse files
committed
mapi_lib: replace GUID::compare with GUID::operator<=>
1 parent b644296 commit b041d63

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

exch/ews/structures.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2787,7 +2787,7 @@ tExtendedFieldURI::tExtendedFieldURI(uint16_t type, const PROPERTY_NAME& propnam
27872787
PropertyName = propname.pname;
27882788

27892789
auto it = std::find_if(std::begin(propsetIds), std::end(propsetIds),
2790-
[&](const auto& propsetId){ return propsetId->compare(propname.guid) == 0; });
2790+
[&](const auto &propsetId) { return *propsetId == propname.guid; });
27912791
if (it != std::end(propsetIds))
27922792
DistinguishedPropertySetId = Enum::DistinguishedPropertySetType(static_cast<uint8_t>(std::distance(std::begin(propsetIds), it)));
27932793
}

include/gromox/mapidefs.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,6 @@ struct GX_EXPORT GUID {
983983
void to_str(char *, size_t, unsigned int type = 36) const;
984984
bool from_str(const char *);
985985
int compare_4_12(const GUID &) const;
986-
int compare(const GUID &) const;
987986
static GUID random_new();
988987
static const GUID &machine_id();
989988

@@ -993,9 +992,17 @@ struct GX_EXPORT GUID {
993992
uint8_t clock_seq[2];
994993
uint8_t node[6];
995994

996-
/* Same considerations as for FLATUID */
995+
/*
996+
* Same considerations as for FLATUID: because of bad gcc optimization,
997+
* call memcmp directly.
998+
*/
997999
inline bool operator==(const GUID &o) const { return memcmp(this, &o, sizeof(o)) == 0; }
9981000
inline bool operator!=(const GUID &o) const { return !operator==(o); }
1001+
/*
1002+
* EXC2019 evaluates GUID-GUID comparisons (in e.g. restrictions)
1003+
* member-wise and in host order.
1004+
*/
1005+
inline auto operator<=>(const GUID &) const = default;
9991006
};
10001007

10011008
struct GX_EXPORT GUID_ARRAY {

lib/guid2.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,3 @@ int GUID::compare_4_12(const GUID &o) const
353353
auto r = memcmp(clock_seq, o.clock_seq, std::size(clock_seq));
354354
return r != 0 ? r : memcmp(node, o.node, std::size(node));
355355
}
356-
357-
int GUID::compare(const GUID &o) const
358-
{
359-
/*
360-
* EXC2019 also evaluates restrictions (should be the same as the
361-
* outcome of a sort operation) such that GUID fields are compared in
362-
* broken-out fashion, host-order.
363-
*/
364-
if (time_low != o.time_low)
365-
return time_low > o.time_low ? 1 : -1;
366-
return compare_4_12(o);
367-
}

lib/mapi/propval.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,10 @@ int propval_compare(const void *pvalue1, const void *pvalue2, proptype_t proptyp
602602
case PT_GXI_STRING:
603603
return strcasecmp(static_cast<const char *>(pvalue1),
604604
static_cast<const char *>(pvalue2));
605-
case PT_CLSID:
606-
return static_cast<const GUID *>(pvalue1)->compare(*static_cast<const GUID *>(pvalue2));
605+
case PT_CLSID: {
606+
auto c = *static_cast<const GUID *>(pvalue1) <=> *static_cast<const GUID *>(pvalue2);
607+
return c == 0 ? 0 : c < 0 ? -1 : 1;
608+
}
607609
case PT_BINARY: {
608610
auto c = *static_cast<const BINARY *>(pvalue1) <=> *static_cast<const BINARY *>(pvalue2);
609611
return c == 0 ? 0 : c < 0 ? -1 : 1;
@@ -680,9 +682,9 @@ int propval_compare(const void *pvalue1, const void *pvalue2, proptype_t proptyp
680682
if (cmp != 0)
681683
break;
682684
for (size_t i = 0; i < bv1->count; ++i) {
683-
cmp = bv1->pguid[i].compare(bv2->pguid[i]);
684-
if (cmp != 0)
685-
break;
685+
auto c = bv1->pguid[i] <=> bv2->pguid[i];
686+
if (c != 0)
687+
return c < 0 ? -1 : 1;
686688
}
687689
break;
688690
}

tests/utiltest.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ static int t_cmp_binary()
307307
static int t_cmp_guid()
308308
{
309309
GUID g1 = {0x01}, g2 = {0x0100};
310-
assert(g1.compare(g2) < 0);
310+
assert(g1 < g2);
311+
assert(g2 > g1);
312+
assert(g1 == g1);
313+
assert(g2 == g2);
314+
assert(g1 != g2);
311315

312316
char buf[sizeof(FLATUID)];
313317
EXT_PUSH ep;

0 commit comments

Comments
 (0)