Skip to content

Commit

Permalink
AKI-456: Removed support for StringBuffer capacity and Regular Expres…
Browse files Browse the repository at this point in the history
…sions in String
  • Loading branch information
aion-shidokht committed Oct 27, 2019
1 parent f70bd4d commit 347e348
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,30 +171,13 @@ public static void stringBufferAddObject() {

@Callable
public static void stringBufferConstructor() {
StringBuffer sb = new StringBuffer(100);
Blockchain.require(sb.length() == 0);

StringBuffer sb2 = new StringBuffer("MyString");
Blockchain.require(sb2.toString().equals("MyString"));

StringBuffer sb3 = new StringBuffer((CharSequence) "MyString");
Blockchain.require(sb3.toString().equals("MyString"));
}

@Callable
public static void stringBufferInvalidConstructor() {
long energyRemaining = 0l;
boolean exceptionThrown = false;
try {
energyRemaining = Blockchain.getRemainingEnergy();
StringBuffer sb = new StringBuffer(-10000000);
} catch (NegativeArraySizeException e) {
exceptionThrown = true;
Blockchain.require(energyRemaining > Blockchain.getRemainingEnergy());
}
Blockchain.require(exceptionThrown);
}

@Callable
public static void stringBufferInvalidAppend(){
long energyRemaining = 0l;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ public void stringBufferConstructor(){
callStatic("stringBufferConstructor");
}

@Test
public void stringBufferInvalidConstructor(){
callStatic("stringBufferInvalidConstructor");
}

@Test
public void stringBufferInvalidAppend(){
callStatic("stringBufferInvalidAppend");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,7 @@ public class RuntimeMethodFeeSchedule {
public static final int String_avm_subSequence = RT_METHOD_FEE_LEVEL_2; // totalCost - 194;
public static final int String_avm_concat = RT_METHOD_FEE_LEVEL_2; // totalCost - 526; // byte code cost - 426; invoked methods cost - 100;
public static final int String_avm_replace = RT_METHOD_FEE_LEVEL_3; // totalCost - 460; // byte code cost - 360; invoked methods cost - 100;
public static final int String_avm_matches = RT_METHOD_FEE_LEVEL_2; // totalCost - 366; // byte code cost - 266; invoked methods cost - 100;
public static final int String_avm_contains = RT_METHOD_FEE_LEVEL_2; // totalCost - 412; //maximum cost of multiple blocks;
public static final int String_avm_replaceFirst = RT_METHOD_FEE_LEVEL_4; // totalCost - 604; // byte code cost - 504; invoked methods cost - 100;
public static final int String_avm_replaceAll = RT_METHOD_FEE_LEVEL_4; // totalCost - 604; // byte code cost - 504; invoked methods cost - 100;
public static final int String_avm_replace_1 = RT_METHOD_FEE_LEVEL_4; // totalCost - 1092; // byte code cost - 736; invoked methods cost - 356;
public static final int String_avm_toLowerCase = RT_METHOD_FEE_LEVEL_3; // totalCost - 448; // byte code cost - 348; invoked methods cost - 100;
public static final int String_avm_toUpperCase = RT_METHOD_FEE_LEVEL_3; // totalCost - 448; // byte code cost - 348; invoked methods cost - 100;
Expand Down Expand Up @@ -461,12 +458,9 @@ public class RuntimeMethodFeeSchedule {
public static final int System_avm_arraycopy = RT_METHOD_FEE_LEVEL_1; // totalCost - 819; //maximum cost of multiple blocks; // byte code cost - 619; invoked methods cost - 200;

public static final int StringBuffer_avm_constructor = RT_METHOD_FEE_LEVEL_2; // totalCost - 391; // byte code cost - 291; invoked methods cost - 100;
public static final int StringBuffer_avm_constructor_1 = RT_METHOD_FEE_LEVEL_2; // totalCost - 579; // byte code cost - 351; invoked methods cost - 228;
public static final int StringBuffer_avm_constructor_2 = RT_METHOD_FEE_LEVEL_3; // totalCost - 265;
public static final int StringBuffer_avm_constructor_3 = RT_METHOD_FEE_LEVEL_3; // totalCost - 265;
public static final int StringBuffer_avm_length = RT_METHOD_FEE_LEVEL_1; // totalCost - 222; // byte code cost - 122; invoked methods cost - 100;
public static final int StringBuffer_avm_capacity = RT_METHOD_FEE_LEVEL_2; // totalCost - 222; // byte code cost - 122; invoked methods cost - 100;
public static final int StringBuffer_avm_ensureCapacity = RT_METHOD_FEE_LEVEL_2; // totalCost - 228; // byte code cost - 128; invoked methods cost - 100;
public static final int StringBuffer_avm_trimToSize = RT_METHOD_FEE_LEVEL_2; // totalCost - 222; // byte code cost - 122; invoked methods cost - 100;
public static final int StringBuffer_avm_setLength = RT_METHOD_FEE_LEVEL_2; // totalCost - 228; // byte code cost - 128; invoked methods cost - 100;
public static final int StringBuffer_avm_charAt = RT_METHOD_FEE_LEVEL_2; // totalCost - 228; // byte code cost - 128; invoked methods cost - 100;
Expand Down
25 changes: 1 addition & 24 deletions org.aion.avm.rt/src/s/java/lang/String.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,36 +288,13 @@ public String avm_replace(char oldChar, char newChar) {
return new String(this.v.replace(oldChar, newChar));
}

public boolean avm_matches(String regex){
IInstrumentation.attachedThreadInstrumentation.get().chargeEnergy(EnergyCalculator.multiplyLinearValueByMethodFeeLevel2AndAddBase(RuntimeMethodFeeSchedule.String_avm_matches, internalLength()));
lazyLoad();
regex.lazyLoad();
return this.v.matches(regex.v);
}

public boolean avm_contains(CharSequence s){
IInstrumentation.attachedThreadInstrumentation.get().chargeEnergy(EnergyCalculator.multiplyLinearValueByMethodFeeLevel2AndAddBase(RuntimeMethodFeeSchedule.String_avm_contains, internalLength()));
lazyLoad();
((Object)s).lazyLoad();
return this.v.indexOf(s.avm_toString().getUnderlying()) >= 0;
}

public String avm_replaceFirst(String regex, String replacement){
IInstrumentation.attachedThreadInstrumentation.get().chargeEnergy(EnergyCalculator.multiplyLinearValueByMethodFeeLevel2AndAddBase(RuntimeMethodFeeSchedule.String_avm_replaceFirst, internalLength()));
lazyLoad();
regex.lazyLoad();
replacement.lazyLoad();
return new String(this.v.replaceFirst(regex.v, replacement.v));
}

public String avm_replaceAll(String regex, String replacement) {
IInstrumentation.attachedThreadInstrumentation.get().chargeEnergy(EnergyCalculator.multiplyLinearValueByMethodFeeLevel2AndAddBase(RuntimeMethodFeeSchedule.String_avm_replaceAll, internalLength()));
lazyLoad();
regex.lazyLoad();
replacement.lazyLoad();
return new String(this.v.replaceAll(regex.v, replacement.v));
}


public String avm_replace(CharSequence target, CharSequence replacement){
IInstrumentation.attachedThreadInstrumentation.get().chargeEnergy(EnergyCalculator.multiplyLinearValueByMethodFeeLevel2AndAddBase(RuntimeMethodFeeSchedule.String_avm_replace_1, internalLength()));
lazyLoad();
Expand Down
15 changes: 0 additions & 15 deletions org.aion.avm.rt/src/s/java/lang/StringBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public StringBuffer() {
this.v = new java.lang.StringBuffer();
}

public StringBuffer(int capacity) {
IInstrumentation.attachedThreadInstrumentation.get().chargeEnergy(EnergyCalculator.multiplyLinearValueByMethodFeeLevel2AndAddBase(RuntimeMethodFeeSchedule.StringBuffer_avm_constructor_1, java.lang.Math.max(capacity, 0)));
this.v = new java.lang.StringBuffer(capacity);
}

public StringBuffer(String str) {
int lengthForBilling = (null != str)
? str.internalLength()
Expand All @@ -45,16 +40,6 @@ public int avm_length() {
return internalLength();
}

public int avm_capacity() {
IInstrumentation.attachedThreadInstrumentation.get().chargeEnergy(RuntimeMethodFeeSchedule.StringBuffer_avm_capacity);
return this.v.capacity();
}

public void avm_ensureCapacity(int minimumCapacity){
IInstrumentation.attachedThreadInstrumentation.get().chargeEnergy(RuntimeMethodFeeSchedule.StringBuffer_avm_ensureCapacity);
this.v.ensureCapacity(minimumCapacity);
}

public void avm_trimToSize() {
IInstrumentation.attachedThreadInstrumentation.get().chargeEnergy(EnergyCalculator.multiplyLinearValueByMethodFeeLevel2AndAddBase(RuntimeMethodFeeSchedule.StringBuffer_avm_trimToSize, internalLength()));
this.v.trimToSize();
Expand Down

0 comments on commit 347e348

Please sign in to comment.