Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #21323
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Jan Burse <janburse@fastmail.fm> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Substring changes (JDK 1.7) |
| Date | Fri, 11 Jan 2013 10:56:29 +0100 |
| Organization | albasani.net |
| Lines | 39 |
| Message-ID | <kconk8$q09$1@news.albasani.net> (permalink) |
| References | <kcmg8p$7ee$1@news.albasani.net> <dk8ue8p3nml7pv1rj34ojtgtc9i9cdn80n@4ax.com> <kcoi5q$dng$1@news.albasani.net> <g6WdneAGWPt1UHLNnZ2dnUVZ8qSdnZ2d@bt.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-15; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.albasani.net A1trkLRwzDzdpxOt9WaVbc2HK7UjL77iVQ72soCdAeidkgyx+0oDM3wLlfzaCYyMtO7IgViYeEs07xrO7n2f/g== |
| NNTP-Posting-Date | Fri, 11 Jan 2013 09:56:24 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="hdGQfZWg7hC5WZQvlD/OWi3PXiNBpJkTBjIynJxOZlBkeOhI7KmnyxJT55ppRlf0Z6LRE+0GtKRNrupyieOHc6lC7Dche0MBVzIo98vBuSpeGGG9X0T2A+sAmQtCkwOh"; mail-complaints-to="abuse@albasani.net" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0 SeaMonkey/2.15 |
| In-Reply-To | <g6WdneAGWPt1UHLNnZ2dnUVZ8qSdnZ2d@bt.com> |
| Cancel-Lock | sha1:RS5xz7r3MeG8VQ97Ii7/6hTPlgI= |
| Xref | csiph.com comp.lang.java.programmer:21323 |
Show key headers only | View raw
Chris Uppal schrieb:
>> For example I trapped myself doing things like:
>> >
>> > int k = path.lastIndexOf('/');
>> > while (k!=-1) {
>> > String name = path.substring(k+1);
>> > /* do something with name */
>> > path = path.substring(0,k);
>> > k = path.lastIndexOf('/');
>> > }
>> >
> And what's wrong with that ? Seems a sensible approach to me.
>
> If you mean that it's suddenly/significantly/ slower, then I don't believe
> you. (Though I freely admit that there will be a tiny few cases where it
> /does/ matter -- in which cases I will be wrong.)
>
> -- chris
>
>
With the sharing semantics, its complexity is O(n+m), where
n is the length of the string and m is the number of
backslashes. The m counts for the number of creation of
shared String shells.
Without the sharing semantics, when substring copies, its
complexity is O(n^2), assuming m is not too small. In each
of the m interation you do not anymore create a String shell,
but instead in the following statement
path = path.substring(0,k);
you do copy a fair amount of path. JDK 1.7 Update 10 has not
anymore the sharing semantics. So when my m are not too small,
its probably a good idea to rewrite the code.
Bye
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Substring changes (JDK 1.7) Jan Burse <janburse@fastmail.fm> - 2013-01-10 14:38 +0100
Re: Substring changes (JDK 1.7) markspace <markspace@nospam.nospam> - 2013-01-10 08:15 -0800
Re: Substring changes (JDK 1.7) Joshua Cranmer <Pidgeot18@verizon.invalid> - 2013-01-10 10:48 -0600
Re: Substring changes (JDK 1.7) markspace <markspace@nospam.nospam> - 2013-01-10 09:22 -0800
Re: Substring changes (JDK 1.7) Lars Enderin <lars.enderin@telia.com> - 2013-01-10 19:35 +0100
Re: Substring changes (JDK 1.7) Jan Burse <janburse@fastmail.fm> - 2013-01-10 20:08 +0100
Re: Substring changes (JDK 1.7) Jan Burse <janburse@fastmail.fm> - 2013-01-10 20:12 +0100
Re: Substring changes (JDK 1.7) Roedy Green <see_website@mindprod.com.invalid> - 2013-01-10 12:22 -0800
Re: Substring changes (JDK 1.7) Robert Klemme <shortcutter@googlemail.com> - 2013-01-10 22:58 +0100
Re: Substring changes (JDK 1.7) Roedy Green <see_website@mindprod.com.invalid> - 2013-01-10 15:20 -0800
Re: Substring changes (JDK 1.7) Robert Klemme <shortcutter@googlemail.com> - 2013-01-11 07:29 +0100
Re: Substring changes (JDK 1.7) Roedy Green <see_website@mindprod.com.invalid> - 2013-01-10 23:19 -0800
Re: Substring changes (JDK 1.7) Robert Klemme <shortcutter@googlemail.com> - 2013-01-12 17:50 +0100
Re: Substring changes (JDK 1.7) markspace <markspace@nospam.nospam> - 2013-01-12 09:59 -0800
Re: Substring changes (JDK 1.7) Jan Burse <janburse@fastmail.fm> - 2013-01-12 19:14 +0100
Re: Substring changes (JDK 1.7) markspace <markspace@nospam.nospam> - 2013-01-12 10:36 -0800
Re: Substring changes (JDK 1.7) Jan Burse <janburse@fastmail.fm> - 2013-01-13 12:09 +0100
Re: Substring changes (JDK 1.7) Jan Burse <janburse@fastmail.fm> - 2013-01-11 09:23 +0100
Re: Substring changes (JDK 1.7) "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-01-11 08:29 +0000
Re: Substring changes (JDK 1.7) Jan Burse <janburse@fastmail.fm> - 2013-01-11 10:56 +0100
Re: Substring changes (JDK 1.7) Jan Burse <janburse@fastmail.fm> - 2013-01-11 14:30 +0100
csiph-web