I don't believe so.  For the same reason we don't want enhanced on Apple and extended everywhere else.  Better if all platforms do the same thing.<br><br>There may be a case to be made for standardizing on std::regex though, it has many different flavors and has been standardized for some time.<br><br>Maybe llvm::Regex could be rewritten in terms of std::regex, that would enable all the cool flavors for everyone (but I imagine it would tickle some strange compatibility bugs and not be entirely smooth)<br><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 21, 2016 at 6:20 PM Jim Ingham <<a href="mailto:jingham@apple.com">jingham@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So does the build machinery use the one that is supported on that platform if it is available?  They are going to get much wider testing, fixes and even "ENHANCE"ments...<br class="gmail_msg">
<br class="gmail_msg">
Jim<br class="gmail_msg">
<br class="gmail_msg">
> On Sep 21, 2016, at 6:07 PM, Zachary Turner <<a href="mailto:zturner@google.com" class="gmail_msg" target="_blank">zturner@google.com</a>> wrote:<br class="gmail_msg">
><br class="gmail_msg">
> Windows :)<br class="gmail_msg">
><br class="gmail_msg">
> But that was before std::regex. In theory std::regex would work everywhere (although idk how it performs)<br class="gmail_msg">
> On Wed, Sep 21, 2016 at 6:04 PM Jim Ingham <<a href="mailto:jingham@apple.com" class="gmail_msg" target="_blank">jingham@apple.com</a>> wrote:<br class="gmail_msg">
> It seems a little odd that llvm has its own forked copy of Henry Spencer's old regular expression engine?  Are there platforms we care about that don't have a maintained version of exactly the same code?<br class="gmail_msg">
><br class="gmail_msg">
> Jim<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> > On Sep 21, 2016, at 5:42 PM, Zachary Turner <<a href="mailto:zturner@google.com" class="gmail_msg" target="_blank">zturner@google.com</a>> wrote:<br class="gmail_msg">
> ><br class="gmail_msg">
> > I'll try to address the Regex issue this week (by making everything use llvm extended mode regexes).  If someone feels up to the challenge, adding support for \d \s etc etc to llvm's regex implementation would make a lot of people very happy.<br class="gmail_msg">
> ><br class="gmail_msg">
> > On Wed, Sep 21, 2016 at 5:38 PM Jim Ingham <<a href="mailto:jingham@apple.com" class="gmail_msg" target="_blank">jingham@apple.com</a>> wrote:<br class="gmail_msg">
> ><br class="gmail_msg">
> > > On Sep 21, 2016, at 5:25 PM, Greg Clayton via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" class="gmail_msg" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br class="gmail_msg">
> > ><br class="gmail_msg">
> > > Yep, and we can't have any regex objects in LLDB using those because they will only work on Apple and we don't want code like:<br class="gmail_msg">
> > ><br class="gmail_msg">
> > > #if defined(__APPLE__)<br class="gmail_msg">
> > >   RegularExpression e("\s+");<br class="gmail_msg">
> > > #else<br class="gmail_msg">
> > >   RegularExpression e("[ \t]+");<br class="gmail_msg">
> > > #endif<br class="gmail_msg">
> > ><br class="gmail_msg">
> > > I know "\s" is probably extended, so this was a bad example, but you get my drift.<br class="gmail_msg">
> ><br class="gmail_msg">
> > Nope, sadly for extended you have to say [[:space:]].  To avoid the #define problem, we could require only extended regular expressions in lldb code, but let users type the more convenient enhanced one wherever the command line uses them.  But beyond these convenient shortcuts there probably aren't that many additions that would be useful for the kind of regular expressions our users are likely to write.  If we ever provide "-r" option to "memory find" the byte literal extension might come in handy.  But I don't think that justifies making MacOS builds different.<br class="gmail_msg">
> ><br class="gmail_msg">
> > If it really bothered us we could go get a more modern regex engine from somewhere (rip it out of Tcl or something like that...)<br class="gmail_msg">
> ><br class="gmail_msg">
> > Jim<br class="gmail_msg">
> ><br class="gmail_msg">
> ><br class="gmail_msg">
> > ><br class="gmail_msg">
> > > Greg<br class="gmail_msg">
> > ><br class="gmail_msg">
> > >> On Sep 21, 2016, at 5:19 PM, Zachary Turner <<a href="mailto:zturner@google.com" class="gmail_msg" target="_blank">zturner@google.com</a>> wrote:<br class="gmail_msg">
> > >><br class="gmail_msg">
> > >> That sounds like a plan.  BTW, extended is the one that everyone supports, enhanced is the one that only apple supports.<br class="gmail_msg">
> > >><br class="gmail_msg">
> > >> On Wed, Sep 21, 2016 at 5:18 PM Greg Clayton <<a href="mailto:gclayton@apple.com" class="gmail_msg" target="_blank">gclayton@apple.com</a>> wrote:<br class="gmail_msg">
> > >> And we should check for any "extended" mode regex stuff and get rid of it since as you said they are not portable. They tend to be shortcuts for classes of objects and we can just fix the regex to be more explicit about it. For now we would keep the lldb_private::RegularExpression class, have it have a llvm::Regex member and then lldbassert if the regex fails to compile so we can catch any extended cruft that we might miss so we can fix it...<br class="gmail_msg">
> > >><br class="gmail_msg">
> > >>> On Sep 21, 2016, at 5:15 PM, Greg Clayton <<a href="mailto:gclayton@apple.com" class="gmail_msg" target="_blank">gclayton@apple.com</a>> wrote:<br class="gmail_msg">
> > >>><br class="gmail_msg">
> > >>> To be clear: if we can make StringRef work efficiently, I am fine with that. We can just cut over to using llvm::Regex where it uses the start and end pointer. I would just like to avoid making string copies for no reason. I don't have anything against using StringRef as long as we do it efficiently.<br class="gmail_msg">
> > >>><br class="gmail_msg">
> > >>> Greg<br class="gmail_msg">
> > >>><br class="gmail_msg">
> > >>><br class="gmail_msg">
> > >>>> On Sep 21, 2016, at 5:13 PM, Greg Clayton via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" class="gmail_msg" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>><br class="gmail_msg">
> > >>>>> On Sep 21, 2016, at 4:43 PM, Zachary Turner <<a href="mailto:zturner@google.com" class="gmail_msg" target="_blank">zturner@google.com</a>> wrote:<br class="gmail_msg">
> > >>>>><br class="gmail_msg">
> > >>>>> You need to duplicate something on the heap once when you execute the regex.  And in turn you save tens or hundreds or copies on the way there because of inefficient string usage.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> Where? please show this.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> I see the following callers:<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>        const char *class_name =<br class="gmail_msg">
> > >>>>            iterator->second->GetClassName().AsCString("<unknown>");<br class="gmail_msg">
> > >>>>        if (regex_up && class_name &&<br class="gmail_msg">
> > >>>>            !regex_up->Execute(llvm::StringRef(class_name)))<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> You are adding a strlen() call here to construct the StringRef, not saving anything.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> bool CommandObjectRegexCommand::DoExecute(const char *command,<br class="gmail_msg">
> > >>>>                                        CommandReturnObject &result) {<br class="gmail_msg">
> > >>>> if (command) {<br class="gmail_msg">
> > >>>>  EntryCollection::const_iterator pos, end = m_entries.end();<br class="gmail_msg">
> > >>>>  for (pos = m_entries.begin(); pos != end; ++pos) {<br class="gmail_msg">
> > >>>>    RegularExpression::Match regex_match(m_max_matches);<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>    if (pos->regex.Execute(command, &regex_match)) {<br class="gmail_msg">
> > >>>>      std::string new_command(pos->command);<br class="gmail_msg">
> > >>>>      std::string match_str;<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved. Just wasted time with strlen in StringRef constructor.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>  DataVisualization::Categories::ForEach(<br class="gmail_msg">
> > >>>>      [&regex, &result](const lldb::TypeCategoryImplSP &category_sp) -> bool {<br class="gmail_msg">
> > >>>>        if (regex) {<br class="gmail_msg">
> > >>>>          bool escape = true;<br class="gmail_msg">
> > >>>>          if (regex->GetText() == category_sp->GetName()) {<br class="gmail_msg">
> > >>>>            escape = false;<br class="gmail_msg">
> > >>>>          } else if (regex->Execute(llvm::StringRef::withNullAsEmpty(<br class="gmail_msg">
> > >>>>                         category_sp->GetName()))) {<br class="gmail_msg">
> > >>>>            escape = false;<br class="gmail_msg">
> > >>>>          }<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>          if (escape)<br class="gmail_msg">
> > >>>>            return true;<br class="gmail_msg">
> > >>>>        }<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved. Just wasted time with strlen in StringRef constructor.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>    TypeCategoryImpl::ForEachCallbacks<FormatterType> foreach;<br class="gmail_msg">
> > >>>>    foreach<br class="gmail_msg">
> > >>>>      .SetExact([&result, &formatter_regex, &any_printed](<br class="gmail_msg">
> > >>>>                    ConstString name,<br class="gmail_msg">
> > >>>>                    const FormatterSharedPointer &format_sp) -> bool {<br class="gmail_msg">
> > >>>>        if (formatter_regex) {<br class="gmail_msg">
> > >>>>          bool escape = true;<br class="gmail_msg">
> > >>>>          if (name.GetStringRef() == formatter_regex->GetText()) {<br class="gmail_msg">
> > >>>>            escape = false;<br class="gmail_msg">
> > >>>>          } else if (formatter_regex->Execute(name.GetStringRef())) {<br class="gmail_msg">
> > >>>>            escape = false;<br class="gmail_msg">
> > >>>>          }<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved. Just wasted time with strlen in StringRef constructor.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>  bool ParseCoordinate(const char *id_cstr) {<br class="gmail_msg">
> > >>>>    RegularExpression regex;<br class="gmail_msg">
> > >>>>    RegularExpression::Match regex_match(3);<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>    llvm::StringRef id_ref = llvm::StringRef::withNullAsEmpty(id_cstr);<br class="gmail_msg">
> > >>>>    bool matched = false;<br class="gmail_msg">
> > >>>>    if (regex.Compile(llvm::StringRef("^([0-9]+),([0-9]+),([0-9]+)$")) &&<br class="gmail_msg">
> > >>>>        regex.Execute(id_ref, &regex_match))<br class="gmail_msg">
> > >>>>      matched = true;<br class="gmail_msg">
> > >>>>    else if (regex.Compile(llvm::StringRef("^([0-9]+),([0-9]+)$")) &&<br class="gmail_msg">
> > >>>>             regex.Execute(id_ref, &regex_match))<br class="gmail_msg">
> > >>>>      matched = true;<br class="gmail_msg">
> > >>>>    else if (regex.Compile(llvm::StringRef("^([0-9]+)$")) &&<br class="gmail_msg">
> > >>>>             regex.Execute(id_ref, &regex_match))<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved. Just wasted time with strlen in StringRef constructor.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> void DWARFCompileUnit::ParseProducerInfo() {<br class="gmail_msg">
> > >>>> m_producer_version_major = UINT32_MAX;<br class="gmail_msg">
> > >>>> m_producer_version_minor = UINT32_MAX;<br class="gmail_msg">
> > >>>> m_producer_version_update = UINT32_MAX;<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> const DWARFDebugInfoEntry *die = GetCompileUnitDIEPtrOnly();<br class="gmail_msg">
> > >>>> if (die) {<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>  const char *producer_cstr = die->GetAttributeValueAsString(<br class="gmail_msg">
> > >>>>      m_dwarf2Data, this, DW_AT_producer, NULL);<br class="gmail_msg">
> > >>>>  if (producer_cstr) {<br class="gmail_msg">
> > >>>>    RegularExpression llvm_gcc_regex(<br class="gmail_msg">
> > >>>>        llvm::StringRef("^4\\.[012]\\.[01] \\(Based on Apple "<br class="gmail_msg">
> > >>>>                        "Inc\\. build [0-9]+\\) \\(LLVM build "<br class="gmail_msg">
> > >>>>                        "[\\.0-9]+\\)$"));<br class="gmail_msg">
> > >>>>    if (llvm_gcc_regex.Execute(llvm::StringRef(producer_cstr))) {<br class="gmail_msg">
> > >>>>      m_producer = eProducerLLVMGCC;<br class="gmail_msg">
> > >>>>    } else if (strstr(producer_cstr, "clang")) {<br class="gmail_msg">
> > >>>>      static RegularExpression g_clang_version_regex(<br class="gmail_msg">
> > >>>>          llvm::StringRef("clang-([0-9]+)\\.([0-9]+)\\.([0-9]+)"));<br class="gmail_msg">
> > >>>>      RegularExpression::Match regex_match(3);<br class="gmail_msg">
> > >>>>      if (g_clang_version_regex.Execute(llvm::StringRef(producer_cstr),<br class="gmail_msg">
> > >>>>                                        &regex_match)) {<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved. Just wasted time with strlen in StringRef constructor (2 of them mind you).<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> void DWARFDebugPubnamesSet::Find(<br class="gmail_msg">
> > >>>>  const RegularExpression &regex,<br class="gmail_msg">
> > >>>>  std::vector<dw_offset_t> &die_offset_coll) const {<br class="gmail_msg">
> > >>>> DescriptorConstIter pos;<br class="gmail_msg">
> > >>>> DescriptorConstIter end = m_descriptors.end();<br class="gmail_msg">
> > >>>> for (pos = m_descriptors.begin(); pos != end; ++pos) {<br class="gmail_msg">
> > >>>>  if (regex.Execute(pos->name.c_str()))<br class="gmail_msg">
> > >>>>    die_offset_coll.push_back(m_header.die_offset + pos->offset);<br class="gmail_msg">
> > >>>> }<br class="gmail_msg">
> > >>>> }<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved. Just wasted time with strlen in StringRef constructor (2 of them mind you).<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>    std::string slice_str;<br class="gmail_msg">
> > >>>>    if (reg_info_dict->GetValueForKeyAsString("slice", slice_str, nullptr)) {<br class="gmail_msg">
> > >>>>      // Slices use the following format:<br class="gmail_msg">
> > >>>>      //  REGNAME[MSBIT:LSBIT]<br class="gmail_msg">
> > >>>>      // REGNAME - name of the register to grab a slice of<br class="gmail_msg">
> > >>>>      // MSBIT - the most significant bit at which the current register value<br class="gmail_msg">
> > >>>>      // starts at<br class="gmail_msg">
> > >>>>      // LSBIT - the least significant bit at which the current register value<br class="gmail_msg">
> > >>>>      // ends at<br class="gmail_msg">
> > >>>>      static RegularExpression g_bitfield_regex(<br class="gmail_msg">
> > >>>>          llvm::StringRef("([A-Za-z_][A-Za-z0-9_]*)\\[([0-9]+):([0-9]+)\\]"));<br class="gmail_msg">
> > >>>>      RegularExpression::Match regex_match(3);<br class="gmail_msg">
> > >>>>      if (g_bitfield_regex.Execute(slice_str, &regex_match)) {<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> void SourceManager::File::FindLinesMatchingRegex(<br class="gmail_msg">
> > >>>>  RegularExpression &regex, uint32_t start_line, uint32_t end_line,<br class="gmail_msg">
> > >>>>  std::vector<uint32_t> &match_lines) {<br class="gmail_msg">
> > >>>> match_lines.clear();<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> if (!LineIsValid(start_line) ||<br class="gmail_msg">
> > >>>>    (end_line != UINT32_MAX && !LineIsValid(end_line)))<br class="gmail_msg">
> > >>>>  return;<br class="gmail_msg">
> > >>>> if (start_line > end_line)<br class="gmail_msg">
> > >>>>  return;<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> for (uint32_t line_no = start_line; line_no < end_line; line_no++) {<br class="gmail_msg">
> > >>>>  std::string buffer;<br class="gmail_msg">
> > >>>>  if (!GetLine(line_no, buffer))<br class="gmail_msg">
> > >>>>    break;<br class="gmail_msg">
> > >>>>  if (regex.Execute(buffer)) {<br class="gmail_msg">
> > >>>>    match_lines.push_back(line_no);<br class="gmail_msg">
> > >>>>  }<br class="gmail_msg">
> > >>>> }<br class="gmail_msg">
> > >>>> }<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> static dw_offset_t<br class="gmail_msg">
> > >>>> FindCallbackString(SymbolFileDWARF *dwarf2Data, DWARFCompileUnit *cu,<br class="gmail_msg">
> > >>>>                 DWARFDebugInfoEntry *die, const dw_offset_t next_offset,<br class="gmail_msg">
> > >>>>                 const uint32_t curr_depth, void *userData) {<br class="gmail_msg">
> > >>>> FindCallbackStringInfo *info = (FindCallbackStringInfo *)userData;<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> if (!die)<br class="gmail_msg">
> > >>>>  return next_offset;<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> const char *die_name = die->GetName(dwarf2Data, cu);<br class="gmail_msg">
> > >>>> if (!die_name)<br class="gmail_msg">
> > >>>>  return next_offset;<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> if (info->regex) {<br class="gmail_msg">
> > >>>>  if (info->regex->Execute(llvm::StringRef(die_name)))<br class="gmail_msg">
> > >>>>    info->die_offsets.push_back(die->GetOffset());<br class="gmail_msg">
> > >>>> } else {<br class="gmail_msg">
> > >>>>  if ((info->ignore_case ? strcasecmp(die_name, info->name)<br class="gmail_msg">
> > >>>>                         : strcmp(die_name, info->name)) == 0)<br class="gmail_msg">
> > >>>>    info->die_offsets.push_back(die->GetOffset());<br class="gmail_msg">
> > >>>> }<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> // Just return the current offset to parse the next CU or DIE entry<br class="gmail_msg">
> > >>>> return next_offset;<br class="gmail_msg">
> > >>>> }<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> bool Get_Impl(ConstString key, MapValueType &value,<br class="gmail_msg">
> > >>>>              lldb::RegularExpressionSP *dummy) {<br class="gmail_msg">
> > >>>>  llvm::StringRef key_str = key.GetStringRef();<br class="gmail_msg">
> > >>>>  std::lock_guard<std::recursive_mutex> guard(m_format_map.mutex());<br class="gmail_msg">
> > >>>>  MapIterator pos, end = m_format_map.map().end();<br class="gmail_msg">
> > >>>>  for (pos = m_format_map.map().begin(); pos != end; pos++) {<br class="gmail_msg">
> > >>>>    lldb::RegularExpressionSP regex = pos->first;<br class="gmail_msg">
> > >>>>    if (regex->Execute(key_str)) {<br class="gmail_msg">
> > >>>>      value = pos->second;<br class="gmail_msg">
> > >>>>      return true;<br class="gmail_msg">
> > >>>>    }<br class="gmail_msg">
> > >>>>  }<br class="gmail_msg">
> > >>>>  return false;<br class="gmail_msg">
> > >>>> }<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>        PacketResult echo_packet_result =<br class="gmail_msg">
> > >>>>            SendPacketNoLock(llvm::StringRef(echo_packet, echo_packet_len));<br class="gmail_msg">
> > >>>>        if (echo_packet_result == PacketResult::Success) {<br class="gmail_msg">
> > >>>>          const uint32_t max_retries = 3;<br class="gmail_msg">
> > >>>>          uint32_t successful_responses = 0;<br class="gmail_msg">
> > >>>>          for (uint32_t i = 0; i < max_retries; ++i) {<br class="gmail_msg">
> > >>>>            StringExtractorGDBRemote echo_response;<br class="gmail_msg">
> > >>>>            echo_packet_result = WaitForPacketWithTimeoutMicroSecondsNoLock(<br class="gmail_msg">
> > >>>>                echo_response, timeout_usec, false);<br class="gmail_msg">
> > >>>>            if (echo_packet_result == PacketResult::Success) {<br class="gmail_msg">
> > >>>>              ++successful_responses;<br class="gmail_msg">
> > >>>>              if (response_regex.Execute(echo_response.GetStringRef())) {<br class="gmail_msg">
> > >>>>                sync_success = true;<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> OptionValueSP Instruction::ReadArray(FILE *in_file, Stream *out_stream,<br class="gmail_msg">
> > >>>>                                   OptionValue::Type data_type) {<br class="gmail_msg">
> > >>>> bool done = false;<br class="gmail_msg">
> > >>>> char buffer[1024];<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> OptionValueSP option_value_sp(new OptionValueArray(1u << data_type));<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> int idx = 0;<br class="gmail_msg">
> > >>>> while (!done) {<br class="gmail_msg">
> > >>>>  if (!fgets(buffer, 1023, in_file)) {<br class="gmail_msg">
> > >>>>    out_stream->Printf(<br class="gmail_msg">
> > >>>>        "Instruction::ReadArray:  Error reading file (fgets).\n");<br class="gmail_msg">
> > >>>>    option_value_sp.reset();<br class="gmail_msg">
> > >>>>    return option_value_sp;<br class="gmail_msg">
> > >>>>  }<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>  std::string line(buffer);<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>  size_t len = line.size();<br class="gmail_msg">
> > >>>>  if (line[len - 1] == '\n') {<br class="gmail_msg">
> > >>>>    line[len - 1] = '\0';<br class="gmail_msg">
> > >>>>    line.resize(len - 1);<br class="gmail_msg">
> > >>>>  }<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>  if ((line.size() == 1) && line[0] == ']') {<br class="gmail_msg">
> > >>>>    done = true;<br class="gmail_msg">
> > >>>>    line.clear();<br class="gmail_msg">
> > >>>>  }<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>  if (!line.empty()) {<br class="gmail_msg">
> > >>>>    std::string value;<br class="gmail_msg">
> > >>>>    static RegularExpression g_reg_exp(<br class="gmail_msg">
> > >>>>        llvm::StringRef("^[ \t]*([^ \t]+)[ \t]*$"));<br class="gmail_msg">
> > >>>>    RegularExpression::Match regex_match(1);<br class="gmail_msg">
> > >>>>    bool reg_exp_success = g_reg_exp.Execute(line, &regex_match);<br class="gmail_msg">
> > >>>>    if (reg_exp_success)<br class="gmail_msg">
> > >>>>      regex_match.GetMatchAtIndex(line.c_str(), 1, value);<br class="gmail_msg">
> > >>>>    else<br class="gmail_msg">
> > >>>>      value = line;<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> No copy saved.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> I could do on with all 31 call sites, but I will stop. All that was added was inefficiency and requiring us to make a copy of the string before it is used to evaluate. Some of these are evaluated in tight loops, like the searching for type summaries and formats that are regex based. Happens once for each item in a SBValue (and once per child that is displayed...<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>> We could also just un-delete the overload that takes a const char*, then the duplication would only ever happen when you explicitly use a StringRef.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> For execute it is fine to make one that takes a StringRef, but it would just call .str().c_str() and call the other one. We would assume the "const char *" version of execute would be null terminated.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>><br class="gmail_msg">
> > >>>>> I don't agree this should be reverted.  In the process of doing this conversion I eliminated numerous careless string copies.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> As I showed above the opposite was true. We made many calls to strlen to construct the StringRef so we actually made things slower.<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> Greg<br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>>><br class="gmail_msg">
> > >>>>> On Wed, Sep 21, 2016 at 4:38 PM Greg Clayton <<a href="mailto:gclayton@apple.com" class="gmail_msg" target="_blank">gclayton@apple.com</a>> wrote:<br class="gmail_msg">
> > >>>>> This it the perfect example of why not to use a StringRef since the string needs to be null terminated. Why did we change this? Now even if you call this function:<br class="gmail_msg">
> > >>>>><br class="gmail_msg">
> > >>>>> RegularExpression r(...);<br class="gmail_msg">
> > >>>>><br class="gmail_msg">
> > >>>>> r.Execute(".......................", ...)<br class="gmail_msg">
> > >>>>><br class="gmail_msg">
> > >>>>> You will need to duplicate the string on the heap just to execute this. Please revert this. Anything that requires null terminate is not a candidate for converting to StringRef.<br class="gmail_msg">
> > >>>>><br class="gmail_msg">
> > >>>>><br class="gmail_msg">
> > >>>>>> On Sep 21, 2016, at 10:13 AM, Zachary Turner via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" class="gmail_msg" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br class="gmail_msg">
> > >>>>>><br class="gmail_msg">
> > >>>>>> Author: zturner<br class="gmail_msg">
> > >>>>>> Date: Wed Sep 21 12:13:51 2016<br class="gmail_msg">
> > >>>>>> New Revision: 282090<br class="gmail_msg">
> > >>>>>><br class="gmail_msg">
> > >>>>>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=282090&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=282090&view=rev</a><br class="gmail_msg">
> > >>>>>> Log:<br class="gmail_msg">
> > >>>>>> Fix failing regex tests.<br class="gmail_msg">
> > >>>>>><br class="gmail_msg">
> > >>>>>> r282079 converted the regular expression interface to accept<br class="gmail_msg">
> > >>>>>> and return StringRefs instead of char pointers.  In one case<br class="gmail_msg">
> > >>>>>> a null pointer check was converted to an empty string check,<br class="gmail_msg">
> > >>>>>> but this was an incorrect conversion because an empty string<br class="gmail_msg">
> > >>>>>> is a valid regular expression.  Removing this check should<br class="gmail_msg">
> > >>>>>> fix the test failures.<br class="gmail_msg">
> > >>>>>><br class="gmail_msg">
> > >>>>>> Modified:<br class="gmail_msg">
> > >>>>>> lldb/trunk/source/Core/RegularExpression.cpp<br class="gmail_msg">
> > >>>>>><br class="gmail_msg">
> > >>>>>> Modified: lldb/trunk/source/Core/RegularExpression.cpp<br class="gmail_msg">
> > >>>>>> URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegularExpression.cpp?rev=282090&r1=282089&r2=282090&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegularExpression.cpp?rev=282090&r1=282089&r2=282090&view=diff</a><br class="gmail_msg">
> > >>>>>> ==============================================================================<br class="gmail_msg">
> > >>>>>> --- lldb/trunk/source/Core/RegularExpression.cpp (original)<br class="gmail_msg">
> > >>>>>> +++ lldb/trunk/source/Core/RegularExpression.cpp Wed Sep 21 12:13:51 2016<br class="gmail_msg">
> > >>>>>> @@ -102,7 +102,7 @@ bool RegularExpression::Compile(llvm::St<br class="gmail_msg">
> > >>>>>> //---------------------------------------------------------------------<br class="gmail_msg">
> > >>>>>> bool RegularExpression::Execute(llvm::StringRef str, Match *match) const {<br class="gmail_msg">
> > >>>>>> int err = 1;<br class="gmail_msg">
> > >>>>>> -  if (!str.empty() && m_comp_err == 0) {<br class="gmail_msg">
> > >>>>>> +  if (m_comp_err == 0) {<br class="gmail_msg">
> > >>>>>>  // Argument to regexec must be null-terminated.<br class="gmail_msg">
> > >>>>>>  std::string reg_str = str;<br class="gmail_msg">
> > >>>>>>  if (match) {<br class="gmail_msg">
> > >>>>>><br class="gmail_msg">
> > >>>>>><br class="gmail_msg">
> > >>>>>> _______________________________________________<br class="gmail_msg">
> > >>>>>> lldb-commits mailing list<br class="gmail_msg">
> > >>>>>> <a href="mailto:lldb-commits@lists.llvm.org" class="gmail_msg" target="_blank">lldb-commits@lists.llvm.org</a><br class="gmail_msg">
> > >>>>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br class="gmail_msg">
> > >>>>><br class="gmail_msg">
> > >>>><br class="gmail_msg">
> > >>>> _______________________________________________<br class="gmail_msg">
> > >>>> lldb-commits mailing list<br class="gmail_msg">
> > >>>> <a href="mailto:lldb-commits@lists.llvm.org" class="gmail_msg" target="_blank">lldb-commits@lists.llvm.org</a><br class="gmail_msg">
> > >>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br class="gmail_msg">
> > >>><br class="gmail_msg">
> > >><br class="gmail_msg">
> > ><br class="gmail_msg">
> > > _______________________________________________<br class="gmail_msg">
> > > lldb-commits mailing list<br class="gmail_msg">
> > > <a href="mailto:lldb-commits@lists.llvm.org" class="gmail_msg" target="_blank">lldb-commits@lists.llvm.org</a><br class="gmail_msg">
> > > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br class="gmail_msg">
> ><br class="gmail_msg">
><br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div>