Binary/C - range for memcopy

3 views
Skip to first unread message

Daniel Friesen

unread,
Sep 5, 2009, 9:46:09 AM9/5/09
to comm...@googlegroups.com
I've cleaned up the Binary/C proposal. Essay and removed portions are
extracted and moved out of the spec, and I added a section to detail the
abstract api more.

Something that never got settled in my head and was discussed a little
in irc was bbuf[i] = Blob([1,2,3]); Does it trim down to the first,
throw an error, replace later bytes, or insert?

Also another discussed idea was the idea of some sort of subsec or range
function for memcopy to make it more readable, easier to remember, and
consistent.
I'll use .range() to describe, but leave the actual name up to
discussion and a show of hands.

seq.range(4,5); would roughly return: { sequence: this, start: 5, end: 5 };
Basically it's a dead simple object (like opaque cookie) used only by
buffer operations to make memcopy possible.

bufB.append(seq); // append all of seq onto bufB `bufB.copy(seq,
bufB.length, seq.length);`
bufB.append(seq.range(2,6)); // append 2-6 of seq onto the end of bufB
`bufB.copy(seq, bufB.length, 6-2, 2)`
bufB.insert(bufA.range(4,7), 5); // insert 4-7 of bufA into bufB at 5
`bufB.copy(bufA, 6, 7-4, 4);`
...

To be honest I find long methods with a bunch of numeric params like
.copy and .splice confusing. I almost always end up referring back to
documentation to make use of them. This is a nice way to keep numbers
relevant to the data they subsect and make memcopy possible.

--
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

Ash Berlin

unread,
Sep 5, 2009, 9:54:06 AM9/5/09
to comm...@googlegroups.com

I agree that number args can be confusing because the 2nd number can
mean two things:

| blob.range(4,5) | could mean either of the following things:

blob.range({from: 4, to: 5});
blob.range({from: 4, len: 5});

Perhaps we should start using the form of X.func(optionsObj) in more
places?

I'm not commenting on the usefulness or suitability of anything right
now - my head just isn't in the right place to think properly.


Daniel Friesen

unread,
Sep 5, 2009, 10:08:44 AM9/5/09
to comm...@googlegroups.com
On that note, show of hands item #2
https://wiki.mozilla.org/ServerJS/Binary/C/Show_of_hands
Except for methods existing already in the standard jsapi that would
determine what those numbers normally mean.
Personally I favor offset, length; normally though .range seams to
strike me as a start/end

Ash Berlin

unread,
Sep 5, 2009, 10:13:55 AM9/5/09
to comm...@googlegroups.com

Which is why i suggest using named arguments: There is no scope for
ambiguity as to what it means.

Dean Landolt

unread,
Sep 5, 2009, 10:32:24 AM9/5/09
to comm...@googlegroups.com

Or we could go with established js precedent (substring and substr) and call it range and rng

/me ducks

Kris Kowal

unread,
Sep 5, 2009, 6:37:40 PM9/5/09
to comm...@googlegroups.com
On Sat, Sep 5, 2009 at 6:46 AM, Daniel Friesen<nadir.s...@gmail.com> wrote:

> bufB.append(seq);
> // append all of seq onto bufB
> `bufB.copy(seq, bufB.length, seq.length);`

> bufB.append(seq.range(2,6));
> // append 2-6 of seq onto the end of bufB
> `bufB.copy(seq, bufB.length, 6-2, 2)`

> bufB.insert(bufA.range(4,7), 5);
> // insert 4-7 of bufA into bufB at 5
> `bufB.copy(bufA, 6, 7-4, 4);`

The notation seems equitable. range(begin, end) and range(end) are
intuitive to me. So is range(begin, end, step), but that is perhaps
not applicable in this case. I don't think we should specify that it
be an object literal of that particular interface. Perhaps really an
implementation-specific opaque cookie so we are free to experiment for
a while.

Kris Kowal

Daniel Friesen

unread,
Sep 5, 2009, 7:00:41 PM9/5/09
to comm...@googlegroups.com
Dean Landolt wrote:
>
>
> On Sat, Sep 5, 2009 at 10:13 AM, Ash Berlin
> <ash_flu...@firemirror.com <mailto:ash_flu...@firemirror.com>>
Or how about subsection and subsect... heh
Reply all
Reply to author
Forward
0 new messages