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

Refactor Struct class ref/set with cfunc env. #2052

Closed
wants to merge 3 commits into from

Conversation

take-cheeze
Copy link
Contributor

  • Add few tests related to it.
  • Add arena index restore for large struct creating.

@matz
Copy link
Member

matz commented Apr 12, 2014

Why do you want to use mrb_proc_new_cfunc_with_env()?
Because you can?

@take-cheeze
Copy link
Contributor Author

Sorry for incomplete explanations.

(large Struct member getter is Struct member getter of member index 10 or more)

(About the algorithm and advantage.)
Struct member setting and large Struct member getting could be done with constant time with this patch.
Current Struct linear searches all members name to do above.
This should be effective larger the number of members is and how many the number of member assigning times is.

(About the memory and the disadvantage.)
mrb_proc_new_cfunc_with_env will require 1 REnv object and sizeof(mrb_value) * env_size for overhead.
So when applying this patch it will require (REnv × 1 + sizeof(mrb_value) × 1) × (total of Struct member setter and large Struct member getter) per each new Struct define.(Requires 1 env to store member index.)
In additional it needs memory for mruby-proc-ext mrbgem too.

I think constant time member assigning and getting worth the additional memory uses.
Though I don't know how much the mruby-proc-ext dependency worth the algorithm advantage.

@take-cheeze
Copy link
Contributor Author

And I just found that member getter and setter can be shared with all Struct since what it does is all same like ref_func. Just method name would be different.
So memory overhead can be more small.

@take-cheeze
Copy link
Contributor Author

A part of this code is merged so I'll close this and make the Struct with cfunc env with another pull request.
@matz Thank you for merging the test code and arena restore.

@take-cheeze take-cheeze deleted the cfunc_env_struct branch April 24, 2014 13:06
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.

None yet

2 participants