Skip to content

Commit

Permalink
Move endian ops out of bsdiff.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepb committed Feb 23, 2012
1 parent a2ddd85 commit 9682113
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 40 deletions.
20 changes: 18 additions & 2 deletions src/cpp/binding.cc
Expand Up @@ -22,6 +22,11 @@
#include <node_buffer.h>
#include <v8.h>

#include "boost/endian.hpp"
#ifdef BOOST_BIG_ENDIAN
# include "gnuclib/byteswap.h"
#endif

#include "bsdiff.h"

using namespace node;
Expand Down Expand Up @@ -83,6 +88,11 @@ static void AfterDiff(uv_work_t *req) {

if (shim->err != 0) return Error(shim);

#ifdef BOOST_BIG_ENDIAN
for (size_t i = shim->ctrl.size() - 1; i >= 0; --it)
shim->ctrl[i] = bswap_32(shim->ctrl[i]);
#endif

Buffer *ctrl = Buffer::New(reinterpret_cast<char *>(shim->ctrl.data()),
shim->ctrl.size() * sizeof(int));
Buffer *diff = Buffer::New(shim->diff, shim->difflen, DeleteMemory, NULL);
Expand Down Expand Up @@ -177,8 +187,14 @@ Handle<Value> Patch(const Arguments& args) {
async_stub *shim = new async_stub;

const int *ctrldat = reinterpret_cast<int *>(Buffer::Data(ctrl));
const uint32_t ctrllen = Buffer::Length(ctrl);
for (uint32_t i = 0; i < ctrllen; ++i) shim->ctrl.push_back(ctrldat[i]);
const size_t ctrllen = Buffer::Length(ctrl);

#ifdef BOOST_BIG_ENDIAN
for (size_t i = ctrllen - 1; i >= 0; --it)
ctrldat[i] = bswap_32(ctrldat[i]);
#endif

shim->ctrl.assign(ctrldat, ctrldat + ctrllen);

shim->refdat = Buffer::Data(ref);
shim->diff = Buffer::Data(diff);
Expand Down
13 changes: 6 additions & 7 deletions src/cpp/bsdiff.cc
Expand Up @@ -30,7 +30,6 @@
#include <algorithm>
#include <vector>

#include "endian.h"
#include "bsdiff.h"

namespace node_bsdiff {
Expand Down Expand Up @@ -306,13 +305,13 @@ int bsdiff(bsdiff_dat *args) {
xtralen += (scan - lenb) - (lastscan + lenf);

/* add x bytes from oldfile to x bytes from the diff block */
ctrl.push_back(b32le(lenf));
ctrl.push_back(lenf);

/* copy y bytes from the xtra block */
ctrl.push_back(b32le((scan - lenb) - (lastscan + lenf)));
ctrl.push_back((scan - lenb) - (lastscan + lenf));

/* seek forwards in oldfile by z bytes */
ctrl.push_back(b32le((pos - lenb) - (lastpos + lenf)));
ctrl.push_back((pos - lenb) - (lastpos + lenf));

lastscan = scan - lenb;
lastpos = pos - lenb;
Expand Down Expand Up @@ -369,9 +368,9 @@ int bspatch(bsdiff_dat *args) {
while (destIdx < curlen) {

/* Unpack control data */
addN = b32le(ctrl[ctrlpos++]);
copyN = b32le(ctrl[ctrlpos++]);
seekN = b32le(ctrl[ctrlpos++]);
addN = ctrl[ctrlpos++];
copyN = ctrl[ctrlpos++];
seekN = ctrl[ctrlpos++];

/* Sanity-check */
if (destIdx + addN > curlen || srcIdx + addN > reflen ||
Expand Down
31 changes: 0 additions & 31 deletions src/cpp/endian.h

This file was deleted.

0 comments on commit 9682113

Please sign in to comment.