-
Notifications
You must be signed in to change notification settings - Fork 0
Minor review suggestions #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: wip/new-vector
Are you sure you want to change the base?
Conversation
This is complete rewrite of the old scala.collection.immutable.Vector. The design differs from the old one in one important aspect: Instead of a single movable finger (the "display" pointers) it has a fixed finger at each end. These fingers are part of the proper data structure, not a transient optimization. There are no other ways to get to the data in the fingers (it is not part of the main data array), no focus point, and no stabilization. As a side-effect, the data structure is completely immutable and no extra memory fences are required. A second major difference lies in the implementation. Whereas the old Vector uses a single class for collections of all supported sizes, the new one is split into Vector0 to Vector6 for the different dimensions of the main data array.
|
||
override final def iterator: Iterator[A] = | ||
if(this.isInstanceOf[Vector0.type]) Vector.emptyIterator | ||
if(this eq Vector0) Vector.emptyIterator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comparing the instance requires getting the instance first, a type check is faster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uuuh. That's a nice one!
override final def length: Int = | ||
if(this.isInstanceOf[BigVector[_]]) this.asInstanceOf[BigVector[_]].length0 | ||
else prefix1.length | ||
override final def length: Int = this match { | ||
case value: BigVector[_] => value.length0 | ||
case _ => prefix1.length | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't measure the impact but the pattern match creates some unnecessary bytecode instructions:
public final int length();
descriptor: ()I
Code:
0: aload_0
1: instanceof #485 // class scala/collection/immutable/BigVector
4: ifeq 15
7: aload_0
8: checkcast #485 // class scala/collection/immutable/BigVector
11: invokevirtual #488 // Method scala/collection/immutable/BigVector.length0:()I
14: ireturn
15: aload_0
16: invokevirtual #490 // Method prefix1:()[Ljava/lang/Object;
19: arraylength
20: ireturn
public final int length();
descriptor: ()I
Code:
0: aload_0
1: instanceof #490 // class scala/collection/immutable/BigVector
4: ifeq 18
7: aload_0
8: checkcast #490 // class scala/collection/immutable/BigVector
11: invokevirtual #493 // Method scala/collection/immutable/BigVector.length0:()I
14: istore_1
15: goto 24
18: aload_0
19: invokevirtual #495 // Method prefix1:()[Ljava/lang/Object;
22: arraylength
23: istore_1
24: iload_1
25: ireturn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe. Instead of just ireturn
ing, it istore_1
s, goto
s, iload_1
s and then ireturn
s.
hehe, bytecode shedding 🙂 just pick what seems right to you |
No description provided.