You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Anni Du (JIRA)" <ji...@apache.org> on 2018/08/10 15:39:00 UTC

[jira] [Comment Edited] (HBASE-15233) Bytes.toBytes() methods should allow arrays to be re-used

    [ https://issues.apache.org/jira/browse/HBASE-15233?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16576457#comment-16576457 ] 

Anni Du edited comment on HBASE-15233 at 8/10/18 3:38 PM:
----------------------------------------------------------

Suppose we want to convert b to bytes, and we want to reuse it, what's the difference between
{code:java}
byte reuse = new byte[Byte.SIZEOF_LONG]
reuse = Bytes.toBytes(b)
{code}
and
{code:java}
byte reuse = new byte[Byte.SIZEOF_LONG]
Bytes.toBytes(b,reuse)
{code}
 

 


was (Author: adu):
Suppose we want to convert b to bytes, and we want to reuse it, what's the difference between

```

byte reuse = new byte[Byte.SIZEOF_LONG]
reuse = Bytes.toBytes(b)

```

and

```

byte reuse = new byte[Byte.SIZEOF_LONG]
Bytes.toBytes(b,reuse)

```

 

> Bytes.toBytes() methods should allow arrays to be re-used 
> ----------------------------------------------------------
>
>                 Key: HBASE-15233
>                 URL: https://issues.apache.org/jira/browse/HBASE-15233
>             Project: HBase
>          Issue Type: Improvement
>          Components: API
>    Affects Versions: 1.1.3
>            Reporter: Jean-Marc Spaggiari
>            Assignee: Michael Ernest
>            Priority: Minor
>              Labels: beginner
>
> Today we have this:
> {code}
>   public static byte[] toBytes(long val) {
>     byte [] b = new byte[8];
>     for (int i = 7; i > 0; i--) {
>       b[i] = (byte) val;
>       val >>>= 8;
>     }
>     b[0] = (byte) val;
>     return b;
>   }
> {code}
> might be nice to also have this:
> {code}
>   public static byte[] toBytes(long val, byte[] reuse) {
>     for (int i = 7; i > 0; i--) {
>       reuse[i] = (byte) val;
>       val >>>= 8;
>     }
>     reuse[0] = (byte) val;
>     return reuse;
>   }
> {code}
> Same for all the other Bytes.toBytes() methods.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)