[llvm-commits] [llvm] r82707 - in /llvm/trunk: include/llvm/Support/Regex.h lib/Support/Regex.cpp
Chris Lattner
sabre at nondot.org
Thu Sep 24 13:15:51 PDT 2009
Author: lattner
Date: Thu Sep 24 15:15:51 2009
New Revision: 82707
URL: http://llvm.org/viewvc/llvm-project?rev=82707&view=rev
Log:
tidy up, fix a memory leak in Regex::isValid
Modified:
llvm/trunk/include/llvm/Support/Regex.h
llvm/trunk/lib/Support/Regex.cpp
Modified: llvm/trunk/include/llvm/Support/Regex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Regex.h?rev=82707&r1=82706&r2=82707&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Regex.h (original)
+++ llvm/trunk/include/llvm/Support/Regex.h Thu Sep 24 15:15:51 2009
@@ -54,7 +54,6 @@
/// Matches.
/// For this feature to be enabled you must construct the regex using
/// Regex("...", Regex::Sub) constructor.
-
bool match(const StringRef &String, SmallVectorImpl<StringRef> *Matches=0);
private:
struct llvm_regex *preg;
Modified: llvm/trunk/lib/Support/Regex.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Regex.cpp?rev=82707&r1=82706&r2=82707&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Regex.cpp (original)
+++ llvm/trunk/lib/Support/Regex.cpp Thu Sep 24 15:15:51 2009
@@ -10,15 +10,15 @@
// This file implements a POSIX regular expression matcher.
//
//===----------------------------------------------------------------------===//
+
#include "llvm/Support/Regex.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "regex_impl.h"
#include <string>
-
using namespace llvm;
-Regex::Regex(const StringRef ®ex, unsigned Flags)
-{
+
+Regex::Regex(const StringRef ®ex, unsigned Flags) {
unsigned flags = 0;
preg = new struct llvm_regex;
preg->re_endp = regex.end();
@@ -35,26 +35,23 @@
error = llvm_regcomp(preg, regex.data(), flags|REG_EXTENDED|REG_PEND);
}
-bool Regex::isValid(std::string &Error)
-{
+bool Regex::isValid(std::string &Error) {
if (!error)
return true;
size_t len = llvm_regerror(error, preg, NULL, 0);
- char *errbuff = new char[len];
- llvm_regerror(error, preg, errbuff, len);
- Error.assign(errbuff);
+
+ Error.resize(len);
+ llvm_regerror(error, preg, &Error[0], len);
return false;
}
-Regex::~Regex()
-{
+Regex::~Regex() {
llvm_regfree(preg);
delete preg;
}
-bool Regex::match(const StringRef &String, SmallVectorImpl<StringRef> *Matches)
-{
+bool Regex::match(const StringRef &String, SmallVectorImpl<StringRef> *Matches){
unsigned nmatch = Matches ? preg->re_nsub+1 : 0;
if (Matches) {
@@ -81,7 +78,7 @@
// There was a match.
if (Matches) { // match position requested
- for (unsigned i=0;i<nmatch; i++) {
+ for (unsigned i = 0; i != nmatch; ++i) {
if (pm[i].rm_so == -1) {
// this group didn't match
Matches->push_back(StringRef());
More information about the llvm-commits
mailing list