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

Use type tag for hash code in ht_hash_func() #5049

Merged

Conversation

shuujii
Copy link
Contributor

@shuujii shuujii commented Jul 25, 2020

The function corresponding to ht_hash_func() was as follows in the days of
khash implementation (before d78acc7).

mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key)
{
  enum mrb_vtype t = mrb_type(key);
  ...
  switch (t) {
  ...
  default:
    hv = mrb_funcall(mrb, key, "hash", 0);
    h = (khint_t)t ^ (khint_t)mrb_fixnum(hv);
    break;
  }
  ...
}

When switched to the segmented list implementation (d78acc7), this function
was changed as follows.

sg_hash_func(mrb_state *mrb, seglist *t, mrb_value key)
{
  enum mrb_vtype tt = mrb_type(key);
  ...
  switch (tt) {
  ...
  default:
    hv = mrb_funcall(mrb, key, "hash", 0);
    h = (size_t)t ^ (size_t)mrb_fixnum(hv);
    break;
  }
  ...
}

Since the argument t was added, the variable for type tag was changed from
t to tt, but the variable used in the expression of h remained t.

Probably this is an omission of change, so fixed it.

The function corresponding to `ht_hash_func()` was as follows in the days of
khash implementation (before d78acc7).

  ```c
  mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key)
  {
    enum mrb_vtype t = mrb_type(key);
    ...
    switch (t) {
    ...
    default:
      hv = mrb_funcall(mrb, key, "hash", 0);
      h = (khint_t)t ^ (khint_t)mrb_fixnum(hv);
      break;
    }
    ...
  }
  ```

When switched to the segmented list implementation (d78acc7), this function
was changed as follows.

  ```c
  sg_hash_func(mrb_state *mrb, seglist *t, mrb_value key)
  {
    enum mrb_vtype tt = mrb_type(key);
    ...
    switch (tt) {
    ...
    default:
      hv = mrb_funcall(mrb, key, "hash", 0);
      h = (size_t)t ^ (size_t)mrb_fixnum(hv);
      break;
    }
    ...
  }
  ```

Since the argument `t` was added, the variable for type tag was changed from
`t` to `tt`, but the variable used in the expression of `h` remained `t`.

Probably this is an omission of change, so fixed it.
@matz matz merged commit 425b5f3 into mruby:master Jul 25, 2020
12 checks passed
@matz
Copy link
Member

matz commented Jul 25, 2020

Thank you!

@shuujii shuujii deleted the use-type-tag-for-hash-code-in-ht_hash_func branch Oct 19, 2020
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