[jira] [Updated] (TEXT-87) StrBuilder Add Prefix Optimization

2017-06-12 Thread BELUGA BEHR (JIRA)

 [ 
https://issues.apache.org/jira/browse/TEXT-87?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

BELUGA BEHR updated TEXT-87:

Description: 
As a nice differentiation to Java's String Builder, please add an optimization 
for pre-appending.  Create the buffer a little larger and keep a pointer at the 
0-index of the buffer so that pre-appending isn't necessarily a copy operations 
and instead is simply a pointer update and an array value update.

{code}

public StrBuilder(int initialCapacity, int preCapacity);

// So that on something like this, insert(0, 'A'), isn't a guaranteed array copy

/**
 * Inserts the value into this builder.
 *
 * @param index  the index to add at, must be valid
 * @param value  the value to insert
 * @return this, to enable chaining
 * @throws IndexOutOfBoundsException if the index is invalid
 */
public StrBuilder insert(final int index, final char value) {
validateIndex(index);
// if index == 0 and (bufIndex != 0)
// buffer[--bufIndexindex] = value;
// return this;
ensureCapacity(size + 1);
System.arraycopy(buffer, index, buffer, index + 1, size - index);
buffer[index] = value;
size++;
return this;
}
{code}

  was:
As a nice differentiation to Java's String Builder, please add an optimization 
for pre-appending.  Create the buffer a little larger and keep a pointer at the 
0-index of the buffer so that pre-appending isn't necessarily a copy operations 
and instead is simply a pointer update and an array value update.

{code}

public StrBuilder(int initialCapacity, int preCapacity);

// So that on something like this, insert(0, 'A'), isn't a guaranteed array copy

/**
 * Inserts the value into this builder.
 *
 * @param index  the index to add at, must be valid
 * @param value  the value to insert
 * @return this, to enable chaining
 * @throws IndexOutOfBoundsException if the index is invalid
 */
public StrBuilder insert(final int index, final char value) {
validateIndex(index);
// if index == 0 and (bufIndex != 0)
// buffer[bufIndexindex--] = value;
// return this;
ensureCapacity(size + 1);
System.arraycopy(buffer, index, buffer, index + 1, size - index);
buffer[index] = value;
size++;
return this;
}
{code}


> StrBuilder Add Prefix Optimization
> --
>
> Key: TEXT-87
> URL: https://issues.apache.org/jira/browse/TEXT-87
> Project: Commons Text
>  Issue Type: New Feature
>Reporter: BELUGA BEHR
>Priority: Trivial
>
> As a nice differentiation to Java's String Builder, please add an 
> optimization for pre-appending.  Create the buffer a little larger and keep a 
> pointer at the 0-index of the buffer so that pre-appending isn't necessarily 
> a copy operations and instead is simply a pointer update and an array value 
> update.
> {code}
> public StrBuilder(int initialCapacity, int preCapacity);
> // So that on something like this, insert(0, 'A'), isn't a guaranteed array 
> copy
> /**
>  * Inserts the value into this builder.
>  *
>  * @param index  the index to add at, must be valid
>  * @param value  the value to insert
>  * @return this, to enable chaining
>  * @throws IndexOutOfBoundsException if the index is invalid
>  */
> public StrBuilder insert(final int index, final char value) {
> validateIndex(index);
> // if index == 0 and (bufIndex != 0)
> // buffer[--bufIndexindex] = value;
> // return this;
> ensureCapacity(size + 1);
> System.arraycopy(buffer, index, buffer, index + 1, size - index);
> buffer[index] = value;
> size++;
> return this;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Updated] (TEXT-87) StrBuilder Add Prefix Optimization

2017-12-08 Thread Rob Tompkins (JIRA)

 [ 
https://issues.apache.org/jira/browse/TEXT-87?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Rob Tompkins updated TEXT-87:
-
Fix Version/s: 1.x

> StrBuilder Add Prefix Optimization
> --
>
> Key: TEXT-87
> URL: https://issues.apache.org/jira/browse/TEXT-87
> Project: Commons Text
>  Issue Type: New Feature
>Reporter: BELUGA BEHR
>Priority: Trivial
> Fix For: 1.x
>
>
> As a nice differentiation to Java's String Builder, please add an 
> optimization for pre-appending.  Create the buffer a little larger and keep a 
> pointer at the 0-index of the buffer so that pre-appending isn't necessarily 
> a copy operations and instead is simply a pointer update and an array value 
> update.
> {code}
> public StrBuilder(int initialCapacity, int preCapacity);
> // So that on something like this, insert(0, 'A'), isn't a guaranteed array 
> copy
> /**
>  * Inserts the value into this builder.
>  *
>  * @param index  the index to add at, must be valid
>  * @param value  the value to insert
>  * @return this, to enable chaining
>  * @throws IndexOutOfBoundsException if the index is invalid
>  */
> public StrBuilder insert(final int index, final char value) {
> validateIndex(index);
> // if index == 0 and (bufIndex != 0)
> // buffer[--bufIndexindex] = value;
> // return this;
> ensureCapacity(size + 1);
> System.arraycopy(buffer, index, buffer, index + 1, size - index);
> buffer[index] = value;
> size++;
> return this;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)