digitalmars.D - New regex: Find?
- dsimcha (4/4) May 04 2009 Is there an *efficient* way to simply test whether a given string contai...
- Andrei Alexandrescu (5/9) May 04 2009 If you only search once, there will be allocation. However, if you
- Derek Parnell (6/15) May 04 2009 ranslation: No, there isn't "an *efficient* way".
- Andrei Alexandrescu (6/19) May 04 2009 I think your translation omits important information. I meant exactly
- Derek Parnell (12/31) May 04 2009 I know you meant exactly what you said. I did understand the concept tha...
- Andrei Alexandrescu (4/27) May 04 2009 I emphatically think not, as my answer was precise and did not try to
- Derek Parnell (11/14) May 04 2009 I apologize without reservation.
- Georg Wrede (6/10) May 04 2009 Your question can be understood in several ways. Others have answered
- Joel C. Salomon (4/8) May 04 2009 You mean to search for a regex match without constructing the regex
- dsimcha (14/22) May 04 2009 Actually, the behavior Andrei describes is what I wanted: One allocatio...
- Andrei Alexandrescu (7/33) May 04 2009 Ah... Sigh, I meant to implement the short string optimization in the
Is there an *efficient* way to simply test whether a given string contains a given regex in the new std.regex? Using match() and testing for empty works, but this apparently triggers a bunch of unnecessary heap allocation. If not, is this a universal enough feature to warrant an enhancement request?
May 04 2009
dsimcha wrote:Is there an *efficient* way to simply test whether a given string contains a given regex in the new std.regex? Using match() and testing for empty works, but this apparently triggers a bunch of unnecessary heap allocation. If not, is this a universal enough feature to warrant an enhancement request?If you only search once, there will be allocation. However, if you search for the same regex several times there will be no extra allocation so the cost will be amortized. Andrei
May 04 2009
On Mon, 04 May 2009 10:09:56 -0500, Andrei Alexandrescu wrote:dsimcha wrote:ranslation: No, there isn't "an *efficient* way". -- Derek Parnell Melbourne, Australia skype: derek.j.parnellIs there an *efficient* way to simply test whether a given string contains a given regex in the new std.regex? Using match() and testing for empty works, but this apparently triggers a bunch of unnecessary heap allocation. If not, is this a universal enough feature to warrant an enhancement request?If you only search once, there will be allocation. However, if you search for the same regex several times there will be no extra allocation so the cost will be amortized.
May 04 2009
Derek Parnell wrote:On Mon, 04 May 2009 10:09:56 -0500, Andrei Alexandrescu wrote:I think your translation omits important information. I meant exactly what I said: one isolated search can't be currently helped. Repeated searches can. This is because one search triggers the construction of a regex engine, which in turn allocates memory. Andreidsimcha wrote:ranslation: No, there isn't "an *efficient* way".Is there an *efficient* way to simply test whether a given string contains a given regex in the new std.regex? Using match() and testing for empty works, but this apparently triggers a bunch of unnecessary heap allocation. If not, is this a universal enough feature to warrant an enhancement request?If you only search once, there will be allocation. However, if you search for the same regex several times there will be no extra allocation so the cost will be amortized.
May 04 2009
On Mon, 04 May 2009 16:07:58 -0500, Andrei Alexandrescu wrote:Derek Parnell wrote:I know you meant exactly what you said. I did understand the concept that you were putting forward. However, you didn't actually answer the question. Your answer sounds as if it came from a politian. Maybe a compromise then (more polly talk) ... It is not efficient if you are doing one (or a few) finds, however when doing many finds using the same regex it becomes more and more efficient the more you use it. -- Derek Parnell Melbourne, Australia skype: derek.j.parnellOn Mon, 04 May 2009 10:09:56 -0500, Andrei Alexandrescu wrote:I think your translation omits important information. I meant exactly what I said: one isolated search can't be currently helped. Repeated searches can. This is because one search triggers the construction of a regex engine, which in turn allocates memory.dsimcha wrote:ranslation: No, there isn't "an *efficient* way".Is there an *efficient* way to simply test whether a given string contains a given regex in the new std.regex? Using match() and testing for empty works, but this apparently triggers a bunch of unnecessary heap allocation. If not, is this a universal enough feature to warrant an enhancement request?If you only search once, there will be allocation. However, if you search for the same regex several times there will be no extra allocation so the cost will be amortized.
May 04 2009
Derek Parnell wrote:On Mon, 04 May 2009 16:07:58 -0500, Andrei Alexandrescu wrote:I emphatically think not, as my answer was precise and did not try to hide anything. Oh, whatever. AndreiDerek Parnell wrote:I know you meant exactly what you said. I did understand the concept that you were putting forward. However, you didn't actually answer the question. Your answer sounds as if it came from a politian.On Mon, 04 May 2009 10:09:56 -0500, Andrei Alexandrescu wrote:I think your translation omits important information. I meant exactly what I said: one isolated search can't be currently helped. Repeated searches can. This is because one search triggers the construction of a regex engine, which in turn allocates memory.dsimcha wrote:ranslation: No, there isn't "an *efficient* way".Is there an *efficient* way to simply test whether a given string contains a given regex in the new std.regex? Using match() and testing for empty works, but this apparently triggers a bunch of unnecessary heap allocation. If not, is this a universal enough feature to warrant an enhancement request?If you only search once, there will be allocation. However, if you search for the same regex several times there will be no extra allocation so the cost will be amortized.
May 04 2009
On Mon, 04 May 2009 16:45:35 -0500, Andrei Alexandrescu wrote:Your answer sounds as if it came from a politian.I emphatically think not, as my answer was precise and did not try to hide anything. Oh, whatever.I apologize without reservation. I'm the type of person that thinks that if an answer can be stated as yes or no, but with some qualifiations, then the answer ought to be given as yes or no followed by the "however" part. But that's just me, going by the response I get from most everyone I talk to. :-) -- Derek Parnell Melbourne, Australia skype: derek.j.parnell
May 04 2009
dsimcha wrote:Is there an *efficient* way to simply test whether a given string contains a given regex in the new std.regex? Using match() and testing for empty works, but this apparently triggers a bunch of unnecessary heap allocation. If not, is this a universal enough feature to warrant an enhancement request?Your question can be understood in several ways. Others have answered one of these. OTOH, if you just have two strings, out of which the shorter one is a regex, and you want to know whether it is included in the other string, then I suggest using std.string.find which doesn't seem to cause heap allocation, and is very fast.
May 04 2009
dsimcha wrote:Is there an *efficient* way to simply test whether a given string contains a given regex in the new std.regex? Using match() and testing for empty works, but this apparently triggers a bunch of unnecessary heap allocation. If not, is this a universal enough feature to warrant an enhancement request?You mean to search for a regex match without constructing the regex engine? Good luck with that. —Joel Salomon
May 04 2009
== Quote from Joel C. Salomon (joelcsalomon gmail.com)'s articledsimcha wrote:Actually, the behavior Andrei describes is what I wanted: One allocation to construct the regex engine, amortized. However, contrary to what Andrei said, match() apparently allocates additional memory on each call. The following program leaks memory like a sieve when the GC is disabled: import std.regex, core.memory; void main() { string s = "This is only a test. Repeat, this is only a test."; auto r = regex("is.only"); GC.disable; while(true) { auto m = match(s, r); } }Is there an *efficient* way to simply test whether a given string contains a given regex in the new std.regex? Using match() and testing for empty works, but this apparently triggers a bunch of unnecessary heap allocation. If not, is this a universal enough feature to warrant an enhancement request?You mean to search for a regex match without constructing the regex engine? Good luck with that. —Joel Salomon
May 04 2009
dsimcha wrote:== Quote from Joel C. Salomon (joelcsalomon gmail.com)'s articleAh... Sigh, I meant to implement the short string optimization in the regex range, and put it off forever. It was about time it would come back to haunt me :o). Could you please submit an enhancement request to Bugzilla? Maybe with a patch? :o) Andreidsimcha wrote:Actually, the behavior Andrei describes is what I wanted: One allocation to construct the regex engine, amortized. However, contrary to what Andrei said, match() apparently allocates additional memory on each call. The following program leaks memory like a sieve when the GC is disabled: import std.regex, core.memory; void main() { string s = "This is only a test. Repeat, this is only a test."; auto r = regex("is.only"); GC.disable; while(true) { auto m = match(s, r); } }Is there an *efficient* way to simply test whether a given string contains a given regex in the new std.regex? Using match() and testing for empty works, but this apparently triggers a bunch of unnecessary heap allocation. If not, is this a universal enough feature to warrant an enhancement request?You mean to search for a regex match without constructing the regex engine? Good luck with that. —Joel Salomon
May 04 2009