Advertisement
Guest User

Bytecodes of loop VS iterator

a guest
Aug 2nd, 2012
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. /*
  2. *** CODE 1 ***
  3. */
  4. public class Main {
  5. public Main();
  6. Code:
  7. 0: aload_0
  8. 1: invokespecial #8 // Method java/lang/Object."<init>":
  9. ()V
  10. 4: return
  11.  
  12. public static void main(java.lang.String[]);
  13. Code:
  14. // Here is where we created "i" and allocated the List
  15. (I)Ljava/lang/Integer;
  16. 40: aastore
  17. 41: astore_2
  18. 42: aload_2
  19. 43: dup
  20. 44: astore 6
  21. 46: arraylength
  22. 47: istore 5
  23. 49: iconst_0
  24. 50: istore 4
  25. 52: goto 71
  26. 55: aload 6
  27. 57: iload 4
  28. 59: aaload
  29. 60: astore_3
  30. 61: iload_1
  31. 62: aload_3
  32. 63: invokevirtual #22 // Method java/lang/Integer.intValue
  33. :()I
  34. 66: iadd
  35. 67: istore_1
  36. 68: iinc 4, 1
  37. 71: iload 4
  38. 73: iload 5
  39. 75: if_icmplt 55
  40. 78: getstatic #26 // Field java/lang/System.out:Ljava/
  41. io/PrintStream;
  42. 81: iload_1
  43. 82: invokevirtual #32 // Method java/io/PrintStream.printl
  44. n:(I)V
  45. 85: return
  46. }
  47.  
  48.  
  49.  
  50.  
  51. /*
  52. *** CODE 2 ***
  53. */
  54. public class Main {
  55.  
  56. public Main();
  57. Code:
  58. 0: aload_0
  59. 1: invokespecial #8 // Method java/lang/Object."<init>":
  60. ()V
  61. 4: return
  62.  
  63. public static void main(java.lang.String[]);
  64. Code:
  65. // Here is where we created "i" and allocated the List
  66. erator:()Ljava/util/Iterator;
  67. 71: astore 4
  68. 73: goto 94
  69. 76: aload 4
  70. 78: invokeinterface #35, 1 // InterfaceMethod java/util/Iterato
  71. r.next:()Ljava/lang/Object;
  72. 83: checkcast #20 // class java/lang/Integer
  73. 86: astore_3
  74. 87: iload_1
  75. 88: aload_3
  76. 89: invokevirtual #41 // Method java/lang/Integer.intValue
  77. :()I
  78. 92: iadd
  79. 93: istore_1
  80. 94: aload 4
  81. 96: invokeinterface #45, 1 // InterfaceMethod java/util/Iterato
  82. r.hasNext:()Z
  83. 101: ifne 76
  84. 104: getstatic #49 // Field java/lang/System.out:Ljava/
  85. io/PrintStream;
  86. 107: iload_1
  87. 108: invokevirtual #55 // Method java/io/PrintStream.printl
  88. n:(I)V
  89. 111: return
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement