Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make nqp::encode take a buffer, not create it.
  • Loading branch information
jnthn committed Jul 21, 2013
1 parent 38cee07 commit de37343
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -2918,9 +2918,8 @@ private static void stashBytes(ThreadContext tc, SixModelObject res, byte[] byte
}
}
}
public static SixModelObject encode(String str, String encoding, SixModelObject bufType, ThreadContext tc) {
public static SixModelObject encode(String str, String encoding, SixModelObject res, ThreadContext tc) {
try {
SixModelObject res = bufType.st.REPR.allocate(tc, bufType.st);
if (encoding.equals("utf8")) {
stashBytes(tc, res, str.getBytes("UTF-8"));
}
Expand Down
10 changes: 3 additions & 7 deletions src/vm/parrot/ops/nqp.ops
Expand Up @@ -3359,25 +3359,21 @@ inline op nqp_getlexrelcaller(out PMC, in PMC, in STR) :base_core {

=item nqp_encode

Encodes the specified string with the specified encoding into a buffer of
the provided type.
Encodes the specified string with the specified encoding into the provided
empty buffer.

=cut

*/
inline op nqp_encode(out PMC, in STR, in STR, invar PMC) {
PMC *res_type = $4;
PMC *res = $4;
STRING *enc;
STable *res_elem_st;
storage_spec res_elem_ss;
const char *buffer_data;
INTVAL bytes, i;
NativeValue nv;

/* Allocate buffer result. */
PMC *res = REPR(res_type)->allocate(interp, STABLE(res_type));
REPR(res)->initialize(interp, STABLE(res), OBJECT_BODY(res));

/* Transform string to the requested encoding (Parrot considers
* everything as encoded strings rather than having a Buf/Str
* split). */
Expand Down

0 comments on commit de37343

Please sign in to comment.