1717*/
1818// ==============================================================================
1919
20+ #include < xrpl/beast/utility/instrumentation.h>
2021#include < xrpl/protocol/SField.h>
2122
2223#include < map>
@@ -28,6 +29,7 @@ namespace ripple {
2829SField::IsSigning const SField::notSigning;
2930int SField::num = 0 ;
3031std::map<int , SField const *> SField::knownCodeToField;
32+ std::map<std::string, SField const *> SField::knownNameToField;
3133
3234// Give only this translation unit permission to construct SFields
3335struct SField ::private_access_tag_t
@@ -45,7 +47,7 @@ TypedField<T>::TypedField(private_access_tag_t pat, Args&&... args)
4547}
4648
4749// Construct all compile-time SFields, and register them in the knownCodeToField
48- // database :
50+ // and knownNameToField databases :
4951
5052// Use macros for most SField construction to enforce naming conventions.
5153#pragma push_macro("UNTYPED_SFIELD")
@@ -99,7 +101,14 @@ SField::SField(
99101 , signingField(signing)
100102 , jsonName(fieldName.c_str())
101103{
104+ XRPL_ASSERT (
105+ !knownCodeToField.contains (fieldCode),
106+ " ripple::SField::SField(tid,fv,fn,meta,signing) : fieldCode is unique" );
107+ XRPL_ASSERT (
108+ !knownNameToField.contains (fieldName),
109+ " ripple::SField::SField(tid,fv,fn,meta,signing) : fieldName is unique" );
102110 knownCodeToField[fieldCode] = this ;
111+ knownNameToField[fieldName] = this ;
103112}
104113
105114SField::SField (private_access_tag_t , int fc)
@@ -111,6 +120,9 @@ SField::SField(private_access_tag_t, int fc)
111120 , signingField(IsSigning::yes)
112121 , jsonName(fieldName.c_str())
113122{
123+ XRPL_ASSERT (
124+ !knownCodeToField.contains (fieldCode),
125+ " ripple::SField::SField(fc) : fieldCode is unique" );
114126 knownCodeToField[fieldCode] = this ;
115127}
116128
@@ -145,11 +157,11 @@ SField::compare(SField const& f1, SField const& f2)
145157SField const &
146158SField::getField (std::string const & fieldName)
147159{
148- for (auto const & [_, f] : knownCodeToField)
160+ auto it = knownNameToField.find (fieldName);
161+
162+ if (it != knownNameToField.end ())
149163 {
150- (void )_;
151- if (f->fieldName == fieldName)
152- return *f;
164+ return *(it->second );
153165 }
154166 return sfInvalid;
155167}
0 commit comments