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

Tied typed array #2

Merged
merged 4 commits into from Sep 5, 2013
Merged

Tied typed array #2

merged 4 commits into from Sep 5, 2013

Conversation

tobyink
Copy link
Contributor

@tobyink tobyink commented Sep 4, 2013

This introduces an extra dependency (Type::Tie, which itself has a dependency on Hash::FieldHash), so I'd certainly understand if you didn't want to accept it.

However, I think it has some advantages over the current typed array implementation:

  • It's about 60% faster, according to my very basic benchmarking of
my $arr = array_of(Int, 0..99);
$arr->push(0..9) for 0..99
  • It makes List::Objects::WithUtils::Array::Typed into a fairly trivial subclass of List::Objects::WithUtils::Array; apart from the constructor you no longer need to override any methods. (I think this is the main reason for the speed-up.)
  • This is the reason I implemented it to begin with: using the @{} overload no longer bypasses the type checks and coercions, so people can happily do push @{$typedarray}, $value.

avenj added a commit that referenced this pull request Sep 5, 2013
@avenj avenj merged commit 9fbd15d into avenj:master Sep 5, 2013
@avenj
Copy link
Owner

avenj commented Sep 5, 2013

Very cool! Good enough reason to add the extra deps, in my opinion. Thanks!

avenj added a commit that referenced this pull request Sep 5, 2013
  - Add 'hash_of' (List::Objects::WithUtils::Hash::Typed)
     (Toby Inkster - github PR #3)
    These hashes perform type-checking on their values via Type::Tie.

  - List::Objects::WithUtils/Lowu now accept ':functions' import tag
    (':all' without autobox)

  - Array::Type now uses a Type::Tie tied array
     (Toby Inkster - github PR #2)
    This is faster (no more overload or method overrides), and allows for
    'push @$typedarr, $foo' with type coercion/checking.
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