brianloveswords / buffer-crc32

A pure javascript CRC32 algorithm that plays nice with binary data
MIT License
94 stars 29 forks source link

Use typed array to boost performance by 50% #7

Closed ashi009 closed 10 years ago

ashi009 commented 10 years ago

Haven't tested on node 0.6, but added guard in package.json for that

brianloveswords commented 10 years ago

I think a good compromise would be to use Int32Array if it exists, and fall back if it doesn't. So something like:

var CRC_TABLE = makeCRCTable();
//...
function makeCRCTable() {
  var global = this;
  var table = [0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, /*...*/];
  if (global.Int32Array)
    return new Int32Array(table);
  return table;
}

That way it'll still work in all versions of node (and the browser, when browserified). Does that seem alright?

ashi009 commented 10 years ago

Cool, will update the patch

brianloveswords commented 10 years ago

Awesome, thanks!

ashi009 commented 10 years ago

no problem!

brianloveswords commented 10 years ago

v0.2.3 published.