summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/StringRef.cpp
AgeCommit message (Collapse)Author
2025-04-20[llvm] Call hash_combine_range with ranges (NFC) (#136511)Kazu Hirata
2024-10-25[ADT] Use data() and size() within StringRef (NFC) (#113657)Kazu Hirata
This patch uses data() and size() within StringRef instead of Data and Length. This makes it easier to replace Data and Length with std::string_view in the future, which in turn allows us to forward most of StringRef functions to the counterparts in std::string_view.
2024-08-25[llvm] Prefer StringRef::substr to StringRef::slice (NFC) (#105943)Kazu Hirata
S.substr(N) is simpler than S.slice(N, StringRef::npos) and S.slice(N, S.size()). Also, substr is probably better recognizable than slice thanks to std::string_view::substr.
2024-01-31[llvm] Use StringRef::starts_with (NFC)Kazu Hirata
2024-01-12[Support] Use StringRef::ltrim (NFC)Kazu Hirata
2024-01-11[llvm] Use StringRef::consume_front_insensitive (NFC)Kazu Hirata
2023-11-03[Support] Use StringRef::starts_with/ends_with instead of ↵Simon Pilgrim
startswith/endswith. NFC. startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
2023-05-23Add StringRef::consumeInteger(APInt)Thomas Preud'homme
This will be required to allow arbitrary precision support to FileCheck's numeric variables and expressions. Note: as per getAsInteger(), this does not support negative value. If there is interest for that it can be added in a separate patch. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D150878
2023-05-12[llvm] Migrate {starts,ends}with_insensitive to ↵Kazu Hirata
{starts,ends}_with_insensitive (NFC) This patch migrates uses of StringRef::{starts,ends}with_insensitive to StringRef::{starts,ends}_with_insensitive so that we can use names similar to those used in std::string_view. I'm planning to deprecate StringRef::{starts,ends}with_insensitive once the migration is complete across the code base. Differential Revision: https://reviews.llvm.org/D150426
2023-01-15[ADT] Forward some StringRef::find overloads to std::string_viewBenjamin Kramer
These are identical in terms of functionality and performance (checked libc++ and libstdc++). We could do the same for rfind, but that actually has a off-by one on its position argument. StringRef::find(StringRef) seems to be quite a bit more optimized than the standard library one, so leave it alone.
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
2022-10-27[Support] Use find() for faster StringRef::count (NFC)Tatsuyuki Ishi
While profiling InclusionRewriter, it was found that counting lines was so slow that it took up 20% of the processing time. Surely, calling memcmp() of size 1 on every substring in the window isn't a good idea. Use StringRef::find() instead; in the case of N=1 it will forward to memcmp which is much more optimal. For 2<=N<256 it will run the same memcmp loop as we have now, which is still suboptimal but at least does not regress anything. Differential Revision: https://reviews.llvm.org/D133658
2022-10-15[ADT] Introduce StringRef::{starts,ends}_width{,_insensitive}Kazu Hirata
This patch introduces: StringRef::starts_with StringRef::starts_with_insensitive StringRef::ends_with StringRef::ends_with_insensitive to be more compatible with std::string and std::string_view. I'm planning to deprecate the existing functions in favor of the new ones. Differential Revision: https://reviews.llvm.org/D136030
2022-10-09[Support] Add fast path for StringRef::find with needle of length 2.Tatsuyuki Ishi
InclusionRewriter on Windows (CRLF line endings) will exercise this in a hot path. Calling memcmp repeatedly would be highly suboptimal for that use case, so give it a specialized path. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D133660
2022-06-05[ADT] Add edit_distance_insensitive to StringRefNathan James
In some instances its advantageous to calculate edit distances without worrying about casing. Currently to achieve this both strings need to be converted to the same case first, then edit distance can be calculated. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D126159
2022-01-24Move STLFunctionalExtras out of STLExtrasserge-sans-paille
Only using that change in StringRef already decreases the number of preoprocessed lines from 7837621 to 7776151 for LLVMSupport Perhaps more interestingly, it shows that many files were relying on the inclusion of StringRef.h to have the declaration from STLExtras.h. This patch tries hard to patch relevant part of llvm-project impacted by this hidden dependency removal. Potential impact: - "llvm/ADT/StringRef.h" no longer includes <memory>, "llvm/ADT/Optional.h" nor "llvm/ADT/STLExtras.h" Related Discourse thread: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2021-12-02[llvm] Use range-based for loops (NFC)Kazu Hirata
2021-06-25[ADT] Rename StringRef case insensitive methods for clarityMartin Storsjö
Rename functions with the `xx_lower()` names to `xx_insensitive()`. This was requested during the review of D104218. Test names and variables in llvm/unittests/ADT/StringRefTest.cpp that refer to "lower" are renamed to "insensitive" correspondingly. Unused function aliases with the former method names are left in place (without any deprecation attributes) for transition purposes. All references within the monorepo will be changed (with essentially mechanical changes), and then the old names will be removed in a later commit. Also remove the superfluous method names at the start of doxygen comments, for the methods that are touched here. (There are more occurrances of this left in other methods though.) Also remove duplicate doxygen comments from the implementation file. Differential Revision: https://reviews.llvm.org/D104819
2020-05-21[StringRef] Use some trickery to avoid initializing the std::string returned ↵Benjamin Kramer
by upper()/lower()
2020-04-22Make some static class members constexprBenjamin Kramer
This allows them to be ODR used in C++17 mode. NFC.
2020-01-09[APFloat] Fix checked error assert failuresEhud Katz
`APFLoat::convertFromString` returns `Expected` result, which must be "checked" if the LLVM_ENABLE_ABI_BREAKING_CHECKS preprocessor flag is set. To mark an `Expected` result as "checked" we must consume the `Error` within. In many cases, we are only interested in knowing if an error occured, without the need to examine the error info. This is achieved, easily, with the `errorToBool()` API.
2020-01-06[APFloat] Fix compilation warningsEhud Katz
2020-01-06[APFloat] Add recoverable string parsing errors to APFloatEhud Katz
Implementing the APFloat part in PR4745. Differential Revision: https://reviews.llvm.org/D69770
2020-01-01[polly][Support] Un-break polly testsAlexandre Ganea
Previously, the polly unit tests were stuck in a infinite loop. There was an edge case in StringRef::count() introduced by 9f6b13e5cce96066d7262d224c971d93c2724795, where an empty 'Str' would cause the function to never exit. Also fixed usage in polly.
2019-12-24[Support] Fix behavior of StringRef::count with overlapping occurrences, add ↵Johannes Doerfert
tests Summary: Fix the behavior of StringRef::count(StringRef) to not count overlapping occurrences, as is stated in the documentation. Fixes bug https://bugs.llvm.org/show_bug.cgi?id=44072 I added Krzysztof Parzyszek to review this change because a use of this function in HexagonInstrInfo::getInlineAsmLength might depend on the overlapping-behavior. I don't have enough domain knowledge to tell if this change could break anything there. All other uses of this method in LLVM (besides the unit tests) only use single-character search strings. In those cases, search occurrences can not overlap anyway. Patch by Benno (@Bensge) Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D70585
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-07-30Remove trailing spaceFangrui Song
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338293
2017-12-19Fix APFloat from string conversion for InfSerguei Katkov
The method IEEEFloat::convertFromStringSpecials() does not recognize the "+Inf" and "-Inf" strings but these strings are printed for the double Infinities by the IEEEFloat::toString(). This patch adds the "+Inf" and "-Inf" strings to the list of recognized patterns in IEEEFloat::convertFromStringSpecials(). Re-landing after fix. Reviewers: sberg, bogner, majnemer, timshen, rnk, skatkov, gottesmm, bkramer, scanon, anna Reviewed By: anna Subscribers: mkazantsev, FlameTop, llvm-commits, reames, apilipenko Differential Revision: https://reviews.llvm.org/D38030 llvm-svn: 321054
2017-11-28[Support] Merge toLower / toUpper implementationsFrancis Visoiu Mistrih
Merge the ones from StringRef and StringExtras. llvm-svn: 319171
2017-02-14[Support] Add StringRef::getAsDouble.Zachary Turner
Differential Revision: https://reviews.llvm.org/D29918 llvm-svn: 295089
2016-12-11Tweak the core loop in StringRef::find to avoid calling memcmp on everyChandler Carruth
iteration. Instead, load the byte at the needle length, compare it directly, and save it to use in the lookup table of lengths we can skip forward. I also added an annotation to expect that the comparison fails so that the loop gets laid out contiguously without the call to memcpy (and the substantial register shuffling that the ABI requires of that call). Finally, because this behaves especially badly with a needle length of one (by calling memcmp with a zero length) special case that to directly call memchr, which is what we should have been doing anyways. This was motivated by the fact that there are a large number of test cases in 'check-llvm' where FileCheck's performance is dominated by calls to StringRef::find (in a release, no-asserts build). I'm working on patches to generally improve matters there, but this alone was worth a 12.5% improvement in one test case where FileCheck spent 92% of its time in this routine. I experimented a bunch with different minor variations on this theme, for example setting the pointer *at* the last byte and indexing backwards for the call to memcmp. That didn't improve anything on this version and seemed more complex. I also tried other things to make the loop flow more nicely and none worked. =/ It is a bit unfortunate, the generated code here remains pretty gross, but I don't see any obvious ways to improve it. At this point, most of my ideas would be really elaborate: 1) While the remainder of the string is long enough, we could load a 16-byte or 32-byte vector at the address of the last byte and use palignr to rotate that and check the first 15- or 31-bytes at the front of the next segment, essentially pre-loading the first several bytes of the next iteration so we could quickly detect a mismatch in those bytes without an additional memory access. Down side would be the code complexity, having a fallback loop, and likely misaligned vector load. Plus it would make the common case of the last byte not matching somewhat slower (need some extraction from a vector). 2) While we have space, we could do an aligned load of a 16- or 32-byte vector that *contains* the end byte, and use any peceding bytes to have a more precise "no" test, and any subsequent bytes could be saved for the next iteration. This remove any unaligned load penalty, but still requires us to pay the overhead of vector extraction for the cases where we didn't need to do anything other than load and compare the last byte. 3) Try to walk from the last byte in a way that is more friendly to cache and/or memory pre-fetcher considering we have to poke the last byte anyways. No idea if any of these are really worth pursuing though. They all seem somewhat unlikely to yield big wins in practice and to be a lot of work and complexity. So I settled here, which at least seems like a strict improvement over the previous version. llvm-svn: 289373
2016-11-12[Support] Add StringRef::find_lower and contains_lower.Zachary Turner
Differential Revision: https://reviews.llvm.org/D25299 llvm-svn: 286724
2016-09-22Speculative fix for build failures due to consumeInteger.Zachary Turner
A recent patch added support for consumeInteger() and made getAsInteger delegate to this function. A few buildbots are failing as a result with an assertion failure. On a hunch, I tested what happens if I call getAsInteger() on an empty string, and sure enough it crashes the same way that the buildbots are crashing. I confirmed that getAsInteger() on an empty string did not crash before my patch, so I suspect this to be the cause. I also added a unit test for the empty string. llvm-svn: 282170
2016-09-22[Support] Add StringRef::consumeInteger.Zachary Turner
StringRef::getInteger() exists and treats the entire string as an integer of the specified radix, failing if any invalid characters are encountered or the number overflows. Sometimes you might have something like "123456foo" and you want to get the number 123456 and leave the string "foo" remaining. This is similar to what would be possible by using the standard runtime library functions strtoul et al and specifying an end pointer. This patch adds consumeInteger(), which does exactly that. It consumes as much as possible until an invalid character is found, and modifies the StringRef in place so that upon return only the portion of the StringRef after the number remains. Differential Revision: https://reviews.llvm.org/D24778 llvm-svn: 282164
2016-03-18[MCParser] Accept uppercase radix variants 0X and 0BColin LeMahieu
Differential Revision: http://reviews.llvm.org/D14781 llvm-svn: 263802
2015-09-10[ADT] Rewrite the StringRef::find implementation to be simpler, clearer,Chandler Carruth
and tremendously less reliant on the optimizer to fix things. The code is always necessarily looking for the entire length of the string when doing the equality tests in this find implementation, but it previously was needlessly re-checking the size each time among other annoyances. By writing this so simply an ddirectly in terms of memcmp, it also is about 8x faster in a debug build, which in turn makes FileCheck about 2x faster in 'ninja check-llvm'. This saves about 8% of the time for FileCheck-heavy parts of the test suite like the x86 backend tests. llvm-svn: 247269
2015-09-10[ADT] Fix a confusing interface spec and some annoying peculiaritiesChandler Carruth
with the StringRef::split method when used with a MaxSplit argument other than '-1' (which nobody really does today, but which should actually work). The spec claimed both to split up to MaxSplit times, but also to append <= MaxSplit strings to the vector. One of these doesn't make sense. Given the name "MaxSplit", let's go with it being a max over how many *splits* occur, which means the max on how many strings get appended is MaxSplit+1. I'm not actually sure the implementation correctly provided this logic either, as it used a really opaque loop structure. The implementation was also playing weird games with nullptr in the data field to try to rely on a totally opaque hidden property of the split method that returns a pair. Nasty IMO. Replace all of this with what is (IMO) simpler code that doesn't use the pair returning split method, and instead just finds each separator and appends directly. I think this is a lot easier to read, and it most definitely matches the spec. Added some tests that exercise the corner cases around StringRef() and StringRef("") that all now pass. I'll start using this in code in the next commit. llvm-svn: 247249
2015-09-10[ADT] Add a single-character version of the small vector split routineChandler Carruth
on StringRef. Finding and splitting on a single character is substantially faster than doing it on even a single character StringRef -- we immediately get to a *very* tuned memchr call this way. Even nicer, we get to this even in a debug build, shaving 18% off the runtime of TripleTest.Normalization, helping PR23676 some more. llvm-svn: 247244
2014-08-27Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or ↵Craig Topper
just letting them be implicitly created. llvm-svn: 216525
2014-08-21Remove custom implementations of max/min in StringRef that was originally ↵Craig Topper
added to work an old gcc bug. I believe its been fixed by now. llvm-svn: 216156
2014-04-07[C++11] Make use of 'nullptr' in the Support library.Craig Topper
llvm-svn: 205697
2014-03-06Replace OwningPtr<T> with std::unique_ptr<T>.Ahmed Charles
This compiles with no changes to clang/lld/lldb with MSVC and includes overloads to various functions which are used by those projects and llvm which have OwningPtr's as parameters. This should allow out of tree projects some time to move. There are also no changes to libs/Target, which should help out of tree targets have time to move, if necessary. llvm-svn: 203083
2013-10-30Add {start,end}with_lower methods to StringRef.Rui Ueyama
startswith_lower is ocassionally useful and I think worth adding. endwith_lower is added for completeness. Differential Revision: http://llvm-reviews.chandlerc.com/D2041 llvm-svn: 193706
2013-08-24Added const qualifier to StringRef::edit_distance member functionDmitri Gribenko
Patch by Ismail Pazarbasi. llvm-svn: 189162
2013-07-08Revert r185852.Manman Ren
llvm-svn: 185861
2013-07-08StringRef: add DenseMapInfo for StringRef.Manman Ren
Remove the implementation in include/llvm/Support/YAMLTraits.h. Added a DenseMap type DITypeHashMap in DebugInfo.h: DenseMap<std::pair<StringRef, unsigned>, MDNode*> llvm-svn: 185852
2012-12-03Use the new script to sort the includes of every file under lib.Chandler Carruth
Sooooo many of these had incorrect or strange main module includes. I have manually inspected all of these, and fixed the main module include to be the nearest plausible thing I could find. If you own or care about any of these source files, I encourage you to take some time and check that these edits were sensible. I can't have broken anything (I strictly added headers, and reordered them, never removed), but they may not be the headers you'd really like to identify as containing the API being implemented. Many forward declarations and missing includes were added to a header files to allow them to parse cleanly when included first. The main module rule does in fact have its merits. =] llvm-svn: 169131
2012-10-02Improve overflow detection in StringRef::getAsUnsignedInteger().Nick Kledzik
llvm-svn: 165038
2012-05-11[Support/StringRef] Add find_last_not_of and {r,l,}trim.Michael J. Spencer
llvm-svn: 156652
2012-04-23Don't die with an assertion if the Result bitwidth is already correct. ThisChris Lattner
fixes an assert reading "1239123123123123" when the result is already 64-bit. llvm-svn: 155329