- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
pathological outcomes
Sat, 2011-10-01, 00:52
I wrote a heap of code today, I wonder if I can get anyone to give me
some feedback. In the case of the second two commits I wrote every
line today, so don't consider this a completely polished work or
anything. (The first commit I wrote a couple months ago.) You might
want to look if you are interested in two or more of these things:
a) paths
b) classpaths
c) pathologies
d) empaths
Here:
https://github.com/paulp/scala-dev/tree/path-abstraction
Or in diff form:
https://github.com/paulp/scala-dev/compare/master...path-abstraction
There is no feedback guidance. You can just blast some static, it all
sounds the same through these tinny speakers anyway.
Sun, 2011-10-02, 11:27
#2
Re: pathological outcomes
2011/10/1 √iktor Ҡlang :
> Is length-check + substring + equals faster than endsWith? (Guessing you
> wanted speed due to the @inline hint)
I didn't know String had an endsWith method until I inferred it from
your email. This is an illustration of the funny view of the world
one gets after long exposure to implicit conversions. Because in
those situations I'm bent on avoiding the implicit conversion from
String to Seq, and I know Seq has an endsWith method...
One might still choose to avoid it if one is averse to methods
sneakily changing target. (There are probably less contrived traps
here.)
scala> class A(s: String) { def f1(t: String) = s endsWith t ; def
f2(t: String*) = s endsWith t }
defined class A
scala> :javap -c A
Compiled from ""
public class A extends java.lang.Object implements scala.ScalaObject{
public boolean f1(java.lang.String);
Code:
0: aload_0
1: getfield #12; //Field s:Ljava/lang/String;
4: aload_1
5: invokevirtual #17; //Method
java/lang/String.endsWith:(Ljava/lang/String;)Z
8: ireturn
public boolean f2(scala.collection.Seq);
Code:
0: getstatic #29; //Field scala/Predef$.MODULE$:Lscala/Predef$;
3: aload_0
4: getfield #12; //Field s:Ljava/lang/String;
7: invokevirtual #33; //Method
scala/Predef$.augmentString:(Ljava/lang/String;)Lscala/collection/immutable/StringOps;
10: aload_1
11: invokeinterface #38, 2; //InterfaceMethod
scala/collection/IndexedSeqOptimized.endsWith:(Lscala/collection/GenSeq;)Z
16: ireturn
Sun, 2011-10-02, 11:47
#3
Re: pathological outcomes
If speed is important I'd go with String.endsWith and then add a comment about it.
Cheers,
V
> 2011/10/1 √iktor Ҡlang <viktor.klang@gmail.com>:
>> Is length-check + substring + equals faster than endsWith? (Guessing you
>> wanted speed due to the @inline hint)
>
> I didn't know String had an endsWith method until I inferred it from
> your email. This is an illustration of the funny view of the world
> one gets after long exposure to implicit conversions. Because in
> those situations I'm bent on avoiding the implicit conversion from
> String to Seq, and I know Seq has an endsWith method...
>
> One might still choose to avoid it if one is averse to methods
> sneakily changing target. (There are probably less contrived traps
> here.)
>
>
> scala> class A(s: String) { def f1(t: String) = s endsWith t ; def
> f2(t: String*) = s endsWith t }
> defined class A
>
> scala> :javap -c A
> Compiled from "<console>"
> public class A extends java.lang.Object implements scala.ScalaObject{
> public boolean f1(java.lang.String);
> Code:
> 0: aload_0
> 1: getfield #12; //Field s:Ljava/lang/String;
> 4: aload_1
> 5: invokevirtual #17; //Method
> java/lang/String.endsWith:(Ljava/lang/String;)Z
> 8: ireturn
>
> public boolean f2(scala.collection.Seq);
> Code:
> 0: getstatic #29; //Field scala/Predef$.MODULE$:Lscala/Predef$;
> 3: aload_0
> 4: getfield #12; //Field s:Ljava/lang/String;
> 7: invokevirtual #33; //Method
> scala/Predef$.augmentString:(Ljava/lang/String;)Lscala/collection/immutable/StringOps;
> 10: aload_1
> 11: invokeinterface #38, 2; //InterfaceMethod
> scala/collection/IndexedSeqOptimized.endsWith:(Lscala/collection/GenSeq;)Z
> 16: ireturn
Is length-check + substring + equals faster than endsWith? (Guessing you wanted speed due to the @inline hint)
On Oct 1, 2011 1:52 AM, "Paul Phillips" <paulp@improving.org> wrote:> I wrote a heap of code today, I wonder if I can get anyone to give me
> some feedback. In the case of the second two commits I wrote every
> line today, so don't consider this a completely polished work or
> anything. (The first commit I wrote a couple months ago.) You might
> want to look if you are interested in two or more of these things:
>
> a) paths
> b) classpaths
> c) pathologies
> d) empaths
>
> Here:
>
> https://github.com/paulp/scala-dev/tree/path-abstraction
>
> Or in diff form:
>
> https://github.com/paulp/scala-dev/compare/master...path-abstraction
>
> There is no feedback guidance. You can just blast some static, it all
> sounds the same through these tinny speakers anyway.