-
-
Notifications
You must be signed in to change notification settings - Fork 658
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
Add methods to get Map and EReg sizes #10290
Conversation
…into map-and-regexp-size
Oh yeah this also implements #9303 as an added bonus |
Uh.. why is CI not running here? :o Edit: ok, had to manually launch since it's your first contribution here.. weird new feature from github |
Let's separate this into the map and EReg implementations. Also a question: Does the Map.size implementation have linear cost on any target? |
@Simn It unfortunately has a linear cost on Lua and Flash, however there's no way around it (other than to keep track of the size manually) because the languages themselves don't provide any other way to get the size (I believe it's because they both use the same hashmap implementation). I explained it in more detail here if you're curious |
Hmm, I don't like properties that have hidden cost like that... Also, what's with this idiotic new GitHub feature about manually running PRs, wtf... |
To be fair, it's not really a hidden cost because you'd have to do it in Lua/Flash anyways (in other words, it's already a common pattern). Re: GitHub, idek |
Well yes, but as a Haxe user you shouldn't have to be aware of that. I for instance clearly wasn't aware of it because I had to ask you. :D Note that this isn't about the linear cost per-se because I understand that this cannot be avoided on these targets. My concern is that it's a property as opposed to a function because I believe that a correlation between what looks cheap and what is cheap is generally good design. |
Well it is a property (or native method) on all other targets, which is why I added it as one. I suppose it can be changed to a method if needed |
I agree with Simn: Property access shouldn't be O(N), because that's misleading to the reader. |
I'm wary of this change since Lua is not going to have O(1) access speed like folks would expect. I could track the size separately with another field, but this adds overhead (during updates) to a primitive instance type designed for speed.... which is also not what folks would expect. |
@back2dos Noted, will change. |
@jdonaldson What would you suggest then? > Should the compiler throw an error/warning if the method is called multiple times without the map being modified? There's no easy solution, however this should not be the sole reason why it can't be added, as all other targets support it without any issues. |
I mean, ultimately the question becomes if we want this at all. What do people do with the size of maps? I never found this to be particularly useful. |
No, this would add runtime overhead... it would need to be runtime based to be 100% accurate, compiler can't tell this on its own.
This is possible, the map could change behavior if it detects the method is used. However, for larger projects this behavior is a "poison pill", and could degrade performance suddenly when used... which might be surprising and difficult to track down.
This is possible, but it would then diverge from "vanilla" Lua behavior, which I would want to avoid for such a primitive type.
That's the way I'm leaning, sadly :(
Lua is probably one of the trickiest targets that Haxe supports. I'm fine with making a special exception for Lua... we've done it before. However, the real question is whether this feature is useful enough on its own for other targets despite this. I'd have to defer to @Simn on that one. |
I personally think people would find it helpful to get the size of the map if they want to do things like:
(Additionally, it seems to be used a decent amount in the compiler, so I don't see the issue here) |
Huh, I thought we already had some sort of I suppose we can address the linear Lua situation via documentation. |
Coming back to this, I can't really remember why I said that this was good but didn't merge it. Could you update the branch? |
I don't think you talked about it here, maybe preparing the targets took a lot of time before haxe release (the last activity probably was in neko PR, which I fixed) |
Yeah I ended up becoming really busy after setting up this pr and never got around to finishing it. At this point, I'd probably have to rebase it in order to include the new Int64Map changes, so I've been meaning to close this one and just open two separate PRs for these changes |
Let's do the following:
|
With #11698 merged I'll go ahead and close here because I don't expect this to be updated. |
This pr adds 2 things:
size
property forMap
, which returns the number of entries in the map.matchedNum()
method forEReg
, which returns the number of captured groups from the match (or throws an error if it hasn't been matched).There is a very good chance that the eval impl won't work at first because eval's code isn't documented very well.
Before this is merged: