Skip to content
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

Vector.fill #10687

Merged
merged 9 commits into from
Mar 25, 2023
Merged

Vector.fill #10687

merged 9 commits into from
Mar 25, 2023

Conversation

RblSb
Copy link
Member

@RblSb RblSb commented Apr 23, 2022

Closes #8040
This is only 2-4 times faster on js (node/chrome), btw.

@Simn
Copy link
Member

Simn commented Apr 23, 2022

I'd expect this to be an instance method.

@RblSb
Copy link
Member Author

RblSb commented Apr 23, 2022

You cannot generate filled non-nullable Vector in instance after new Vector(), so there is both (see #8040 (comment)).

@Simn
Copy link
Member

Simn commented Apr 23, 2022

Oh there are two functions... that is some rather confusing naming. I wonder if we can just support overloading the constructor for this. Not sure if that just works already.

@Gama11
Copy link
Member

Gama11 commented Apr 23, 2022

that is some rather confusing naming.

Is it? The naming makes sense to me.

@tobil4sk
Copy link
Member

If the constructor route isn't possible, I think something like createFilled() would make the purpose more explicit.

@sebthom
Copy link
Contributor

sebthom commented Feb 28, 2023

I'd like to see this improvement too.

@RblSb could you please update your PR and change the name of the factory method from filled to createFilled? I think then we are closer to a consensus.

@sebthom
Copy link
Contributor

sebthom commented Feb 28, 2023

@RblSb Thanks!

@Gama11 @Simn @tobil4sk now that the method is properly named. are there still any objections? if not can anyone of you please merge this? My hands are tied :-)

@kLabz
Copy link
Contributor

kLabz commented Feb 28, 2023

CI is not OK yet

/home/runner/work/haxe/haxe/std/hl/_std/haxe/ds/Vector.hx:28: lines 28-90 : Missing field createFilled required by core type

@sebthom
Copy link
Contributor

sebthom commented Feb 28, 2023

@RblSb The tests are green now but I wonder if the same would need to be done for https://github.com/HaxeFoundation/haxe/blob/development/std/php/_std/haxe/ds/Vector.hx too

@tobil4sk
Copy link
Member

I wonder if we can just support overloading the constructor for this. Not sure if that just works already.

Another option would be to just have the defaultValue as a new optional parameter to the constructor. Would there be any problems with that?

@RblSb
Copy link
Member Author

RblSb commented Mar 1, 2023

@tobil4sk there is a problem #10986

@tobil4sk
Copy link
Member

tobil4sk commented Mar 1, 2023

I mean with a single constructor like this, like proposed in the original issue (nvm, I just saw #9478):

public inline function new(length:Int, ?defaultValue:T) {
	this = new java.NativeArray(length);
	if (defaultValue != null) {
		// fill
	}
}

Since defaultValue is optional, the same constructor could still be called without the defaultValue. Is there any reason why something like this couldn't work?

I wonder if the same would need to be done for https://github.com/HaxeFoundation/haxe/blob/development/std/php/_std/haxe/ds/Vector.hx too

The php implementation is missing @:coreApi meta, could be why the missing fields didn't cause an error.

@tobil4sk
Copy link
Member

tobil4sk commented Mar 1, 2023

@tobil4sk there is a problem #10986

This is only a problem during development, no? Once the Vector constructor overload is complete, the user won't be changing the Vector class so they won't be affected.

@RblSb
Copy link
Member Author

RblSb commented Mar 1, 2023

@tobil4sk there is a problem #10986

This is only a problem during development, no? Once the Vector constructor overload is complete, the user won't be changing the Vector class so they won't be affected.

Yes, but this bug reproduces even if you change any comment in something like std.StringTools, and maybe even with complex user-space code, macros, etc. I would like new Vector(5, 1) little more too, but it just breaks jvm target for now.

@RblSb
Copy link
Member Author

RblSb commented Mar 1, 2023

Vector.get(index):
If index is negative or exceeds this.length, the result is unspecified.

this.length - 1 is probably more correct doc? (or "equals this.length or exceeds it")

@tobil4sk
Copy link
Member

tobil4sk commented Mar 1, 2023

Yes, but this bug reproduces even if you change any comment in something like std.StringTools

So to clarify, adding the extra constructor results in future changes to other classes breaking with the same error? In that case I think it's worth waiting for the issue to be investigated to see if we can use the overload constructor version.

Also, for php you could use the native array_fill method, for example like this: tobil4sk@36dafd8.

@RblSb
Copy link
Member Author

RblSb commented Mar 7, 2023

Should be good for merge

@Simn Simn added this to the Release 4.3 milestone Mar 25, 2023
@Simn Simn self-assigned this Mar 25, 2023
@Simn
Copy link
Member

Simn commented Mar 25, 2023

I'm lowkey nervous about using this quite new overload mechanism on something important like Vector, but I guess it's a good thing because we'll know if it goes wrong very quickly. Will merge this once CI had some time to breathe.

@Simn Simn merged commit f76e900 into HaxeFoundation:development Mar 25, 2023
@RblSb RblSb deleted the vector_fill branch March 25, 2023 11:21
@skial skial mentioned this pull request Mar 29, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[js][java] Performance lost
6 participants