Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use bipush rather than LDC

  • Loading branch information...
commit 942b18e89966e493894514c501297d7ec27f120f 1 parent eda6e4f
@stuartwdouglas stuartwdouglas authored
View
9 src/main/java/org/jboss/classfilewriter/code/CodeAttribute.java
@@ -871,7 +871,14 @@ public void iastore() {
*/
public void iconst(int value) {
if (value < -1 || value > 5) {
- ldc(value);
+ if(value < -128 || value > 127) {
+ ldc(value);
+ } else {
+ writeByte(Opcode.BIPUSH);
+ writeByte(value);
+ currentOffset+=2;
+ advanceFrame(currentFrame.push("I"));
+ }
return;
}
writeByte(Opcode.ICONST_0 + value);
View
9 src/test/java/org/jboss/classfilewriter/test/bytecode/i/IconstTest.java
@@ -43,4 +43,13 @@ public void testIconstToLdc() {
Assert.assertEquals(200, (int) mt.invoke());
}
+ @Test
+ public void testIconstToBipush() {
+ MethodTester<Integer> mt = new MethodTester<Integer>(int.class);
+ CodeAttribute ca = mt.getCodeAttribute();
+ ca.iconst(100);
+ ca.returnInstruction();
+ Assert.assertEquals(100, (int) mt.invoke());
+ }
+
}

0 comments on commit 942b18e

Please sign in to comment.
Something went wrong with that request. Please try again.