@@ -253,28 +253,25 @@ IdentifierNamingCheck::FileStyle IdentifierNamingCheck::getFileStyleFromOptions(
253
253
Styles.resize (SK_Count);
254
254
SmallString<64 > StyleString;
255
255
for (unsigned I = 0 ; I < SK_Count; ++I) {
256
- StyleString = StyleNames[I];
257
- size_t StyleSize = StyleString.size ( );
256
+ size_t StyleSize = StyleNames[I]. size () ;
257
+ StyleString.assign ({StyleNames[I], " HungarianPrefix " } );
258
258
259
- StyleString.append (" HungarianPrefix" );
260
259
auto HPTOpt =
261
260
Options.get <IdentifierNamingCheck::HungarianPrefixType>(StyleString);
262
- if (!HungarianNotation.checkOptionValid (I, StyleString) &&
263
- HPTOpt.hasValue ())
261
+ if (HPTOpt.hasValue () && !HungarianNotation.checkOptionValid (I))
264
262
configurationDiag (" invalid identifier naming option '%0'" ) << StyleString;
265
- StyleString.resize (StyleSize);
266
263
267
- StyleString.append (" IgnoredRegexp" );
264
+ memcpy (&StyleString[StyleSize], " IgnoredRegexp" , 13 );
265
+ StyleString.truncate (StyleSize + 13 );
268
266
StringRef IgnoredRegexpStr = Options.get (StyleString, " " );
269
- StyleString. resize ( StyleSize);
270
- StyleString.append ( " Prefix " );
267
+ memcpy (&StyleString[ StyleSize], " Prefix " , 6 );
268
+ StyleString.truncate (StyleSize + 6 );
271
269
std::string Prefix (Options.get (StyleString, " " ));
272
270
// Fast replacement of [Pre]fix -> [Suf]fix.
273
271
memcpy (&StyleString[StyleSize], " Suf" , 3 );
274
272
std::string Postfix (Options.get (StyleString, " " ));
275
273
memcpy (&StyleString[StyleSize], " Case" , 4 );
276
- StyleString.pop_back ();
277
- StyleString.pop_back ();
274
+ StyleString.pop_back_n (2 );
278
275
auto CaseOptional =
279
276
Options.get <IdentifierNamingCheck::CaseType>(StyleString);
280
277
@@ -311,9 +308,8 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
311
308
if (!EOL)
312
309
EOL = Begin + strlen (Begin);
313
310
314
- const std::vector<const char *> PosList = {
315
- strchr (Begin, ' =' ), strchr (Begin, ' ;' ), strchr (Begin, ' ,' ),
316
- strchr (Begin, ' )' ), EOL};
311
+ const char *PosList[] = {strchr (Begin, ' =' ), strchr (Begin, ' ;' ),
312
+ strchr (Begin, ' ,' ), strchr (Begin, ' )' ), EOL};
317
313
for (const auto &Pos : PosList) {
318
314
if (Pos > Begin)
319
315
EOL = std::min (EOL, Pos);
@@ -408,7 +404,7 @@ IdentifierNamingCheck::IdentifierNamingCheck(StringRef Name,
408
404
IdentifierNamingCheck::~IdentifierNamingCheck () = default ;
409
405
410
406
bool IdentifierNamingCheck::HungarianNotation::checkOptionValid (
411
- int StyleKindIndex, StringRef StyleString ) const {
407
+ int StyleKindIndex) const {
412
408
if ((StyleKindIndex >= SK_EnumConstant) &&
413
409
(StyleKindIndex <= SK_ConstantParameter))
414
410
return true ;
@@ -442,16 +438,21 @@ void IdentifierNamingCheck::HungarianNotation::loadFileConfig(
442
438
443
439
StringRef Section = " HungarianNotation." ;
444
440
445
- SmallString<128 > Buffer;
441
+ SmallString<128 > Buffer = {Section, " General." };
442
+ size_t DefSize = Buffer.size ();
446
443
for (const auto &Opt : HNOpts) {
447
- Buffer.assign ({Section, " General." , Opt});
444
+ Buffer.truncate (DefSize);
445
+ Buffer.append (Opt);
448
446
StringRef Val = Options.get (Buffer, " " );
449
447
if (!Val.empty ())
450
448
HNOption.General [Opt] = Val.str ();
451
449
}
452
450
451
+ Buffer = {Section, " DerivedType." };
452
+ DefSize = Buffer.size ();
453
453
for (const auto &Type : HNDerivedTypes) {
454
- Buffer.assign ({Section, " DerivedType." , Type});
454
+ Buffer.truncate (DefSize);
455
+ Buffer.append (Type);
455
456
StringRef Val = Options.get (Buffer, " " );
456
457
if (!Val.empty ())
457
458
HNOption.DerivedType [Type] = Val.str ();
@@ -463,15 +464,21 @@ void IdentifierNamingCheck::HungarianNotation::loadFileConfig(
463
464
{" WideCharPrinter" , " wchar_t*" },
464
465
{" WideCharArray" , " wchar_t[]" }};
465
466
467
+ Buffer = {Section, " CString." };
468
+ DefSize = Buffer.size ();
466
469
for (const auto &CStr : HNCStrings) {
467
- Buffer.assign ({Section, " CString." , CStr.first });
470
+ Buffer.truncate (DefSize);
471
+ Buffer.append (CStr.first );
468
472
StringRef Val = Options.get (Buffer, " " );
469
473
if (!Val.empty ())
470
474
HNOption.CString [CStr.first ] = Val.str ();
471
475
}
472
476
477
+ Buffer = {Section, " PrimitiveType." };
478
+ DefSize = Buffer.size ();
473
479
for (const auto &PrimType : HungarainNotationPrimitiveTypes) {
474
- Buffer.assign ({Section, " PrimitiveType." , PrimType});
480
+ Buffer.truncate (DefSize);
481
+ Buffer.append (PrimType);
475
482
StringRef Val = Options.get (Buffer, " " );
476
483
if (!Val.empty ()) {
477
484
std::string Type = PrimType.str ();
@@ -480,8 +487,11 @@ void IdentifierNamingCheck::HungarianNotation::loadFileConfig(
480
487
}
481
488
}
482
489
490
+ Buffer = {Section, " UserDefinedType." };
491
+ DefSize = Buffer.size ();
483
492
for (const auto &Type : HungarainNotationUserDefinedTypes) {
484
- Buffer.assign ({Section, " UserDefinedType." , Type});
493
+ Buffer.truncate (DefSize);
494
+ Buffer.append (Type);
485
495
StringRef Val = Options.get (Buffer, " " );
486
496
if (!Val.empty ())
487
497
HNOption.UserDefinedType [Type] = Val.str ();
@@ -796,24 +806,23 @@ void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
796
806
for (size_t I = 0 ; I < SK_Count; ++I) {
797
807
if (!Styles[I])
798
808
continue ;
799
- StyleString = StyleNames[I];
800
- size_t StyleSize = StyleString.size ( );
809
+ size_t StyleSize = StyleNames[I]. size () ;
810
+ StyleString.assign ({StyleNames[I], " HungarianPrefix " } );
801
811
802
- Options.store (Opts, (StyleString + " HungarianPrefix" ).str (),
803
- Styles[I]->HPType );
812
+ Options.store (Opts, StyleString, Styles[I]->HPType );
804
813
805
- StyleString.append (" IgnoredRegexp" );
814
+ memcpy (&StyleString[StyleSize], " IgnoredRegexp" , 13 );
815
+ StyleString.truncate (StyleSize + 13 );
806
816
Options.store (Opts, StyleString, Styles[I]->IgnoredRegexpStr );
807
- StyleString. resize ( StyleSize);
808
- StyleString.append ( " Prefix " );
817
+ memcpy (&StyleString[ StyleSize], " Prefix " , 6 );
818
+ StyleString.truncate (StyleSize + 6 );
809
819
Options.store (Opts, StyleString, Styles[I]->Prefix );
810
820
// Fast replacement of [Pre]fix -> [Suf]fix.
811
821
memcpy (&StyleString[StyleSize], " Suf" , 3 );
812
822
Options.store (Opts, StyleString, Styles[I]->Suffix );
813
823
if (Styles[I]->Case ) {
814
824
memcpy (&StyleString[StyleSize], " Case" , 4 );
815
- StyleString.pop_back ();
816
- StyleString.pop_back ();
825
+ StyleString.pop_back_n (2 );
817
826
Options.store (Opts, StyleString, *Styles[I]->Case );
818
827
}
819
828
}
0 commit comments