Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[TableGen] Use StringRef::substr instead of StringRef::slice (NFC) #139485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

StringRef::substr is shorter here because we can rely on its default
second parameter.

StringRef::substr is shorter here because we can rely on its default
second parameter.
@kazutakahirata kazutakahirata requested a review from jurahul May 12, 2025 01:25
@llvmbot llvmbot added the clang Clang issues not falling into any other category label May 12, 2025
@llvmbot
Copy link
Member

llvmbot commented May 12, 2025

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

StringRef::substr is shorter here because we can rely on its default
second parameter.


Full diff: https://github.com/llvm/llvm-project/pull/139485.diff

1 Files Affected:

  • (modified) clang/utils/TableGen/ClangDiagnosticsEmitter.cpp (+5-5)
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index e72288801a830..e347b89a85d46 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1089,7 +1089,7 @@ Piece *DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
 
     if (End) {
       Parsed.push_back(New<TextPiece>(Text.slice(0, End), "diagtext"));
-      Text = Text.slice(End, StringRef::npos);
+      Text = Text.substr(End);
       if (Text.empty())
         break;
     }
@@ -1103,7 +1103,7 @@ Piece *DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
     // Extract the (optional) modifier.
     size_t ModLength = Text.find_first_of("0123456789<{");
     StringRef Modifier = Text.slice(0, ModLength);
-    Text = Text.slice(ModLength, StringRef::npos);
+    Text = Text.substr(ModLength);
     ModifierType ModType = StringSwitch<ModifierType>{Modifier}
                                .Case("select", MT_Select)
                                .Case("enum_select", MT_EnumSelect)
@@ -1154,7 +1154,7 @@ Piece *DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
       Text = Text.drop_front(); // Drop '<'
       size_t EnumNameLen = Text.find_first_of('>');
       EnumSelect->EnumName = Text.slice(0, EnumNameLen);
-      Text = Text.slice(EnumNameLen, StringRef::npos);
+      Text = Text.substr(EnumNameLen);
       ExpectAndConsume(">");
 
       if (Text[0] != '{')
@@ -1169,7 +1169,7 @@ Piece *DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
           Text = Text.drop_front(); // '%'
           size_t OptionNameLen = Text.find_first_of("{");
           EnumSelect->OptionEnumNames.push_back(Text.slice(0, OptionNameLen));
-          Text = Text.slice(OptionNameLen, StringRef::npos);
+          Text = Text.substr(OptionNameLen);
         } else {
           EnumSelect->OptionEnumNames.push_back({});
         }
@@ -1206,7 +1206,7 @@ Piece *DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
         assert(!Text.empty());
         Plural->OptionPrefixes.push_back(
             New<TextPiece>(Text.slice(0, End), "diagtext"));
-        Text = Text.slice(End, StringRef::npos);
+        Text = Text.substr(End);
         Plural->Options.push_back(
             parseDiagText(Text, StopAt::PipeOrCloseBrace));
         assert(!Text.empty() && "malformed %plural");

@kazutakahirata kazutakahirata merged commit 918cdae into llvm:main May 12, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_StringRef_idiom_clang_slice branch May 12, 2025 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.