Guest User

Untitled

a guest
Feb 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.54 KB | None | 0 0
  1. diff --git a/src/org/jruby/RubyProc.java b/src/org/jruby/RubyProc.java
  2. index 1b9ac4b..296ef11 100644
  3. --- a/src/org/jruby/RubyProc.java
  4. +++ b/src/org/jruby/RubyProc.java
  5. @@ -196,7 +196,7 @@ public class RubyProc extends RubyObject implements JumpTarget {
  6. assert args != null;
  7.  
  8. Ruby runtime = getRuntime();
  9. - Block newBlock = block;//.cloneBlock();
  10. + Block newBlock = block;
  11. JumpTarget jumpTarget = newBlock.getBinding().getFrame().getJumpTarget();
  12.  
  13. try {
  14. diff --git a/src/org/jruby/ast/ListNode.java b/src/org/jruby/ast/ListNode.java
  15. index 0b12e4b..013a0ab 100644
  16. --- a/src/org/jruby/ast/ListNode.java
  17. +++ b/src/org/jruby/ast/ListNode.java
  18. @@ -30,6 +30,7 @@
  19. package org.jruby.ast;
  20.  
  21. import java.util.ArrayList;
  22. +import java.util.Collections;
  23. import java.util.List;
  24. import org.jruby.ast.visitor.NodeVisitor;
  25. import org.jruby.lexer.yacc.ISourcePosition;
  26. @@ -41,6 +42,7 @@ import org.jruby.lexer.yacc.ISourcePosition;
  27. * the editor projects who want position info saved.
  28. */
  29. public class ListNode extends Node {
  30. + private Node firstNode;
  31. private List<Node> list;
  32.  
  33. /**
  34. @@ -51,15 +53,12 @@ public class ListNode extends Node {
  35. */
  36. public ListNode(ISourcePosition position, Node firstNode) {
  37. this(position);
  38. -
  39. - list = new ArrayList<Node>(4);
  40. - list.add(firstNode);
  41. +
  42. + this.firstNode = firstNode;
  43. }
  44.  
  45. public ListNode(ISourcePosition position) {
  46. super(position);
  47. -
  48. - list = new ArrayList<Node>(0);
  49. }
  50.  
  51. public NodeType getNodeType() {
  52. @@ -67,6 +66,13 @@ public class ListNode extends Node {
  53. }
  54.  
  55. public ListNode add(Node node) {
  56. + if (firstNode == null) {
  57. + firstNode = node;
  58. + return this;
  59. + } else if (list == null) {
  60. + list = new ArrayList<Node>(4);
  61. + }
  62. +
  63. // Ruby Grammar productions return plenty of nulls.
  64. if (node == null || node == NilImplicitNode.NIL) {
  65. list.add(NilImplicitNode.NIL);
  66. @@ -88,15 +94,31 @@ public class ListNode extends Node {
  67. public ListNode prepend(Node node) {
  68. // Ruby Grammar productions return plenty of nulls.
  69. if (node == null) return this;
  70. -
  71. - list.add(0, node);
  72. +
  73. + if (firstNode != null) {
  74. + if (list == null) {
  75. + list = new ArrayList<Node>(4);
  76. + }
  77. + list.add(0, firstNode);
  78. + firstNode = node;
  79. + } else {
  80. + firstNode = node;
  81. + }
  82.  
  83. setPosition(getPosition().union(node.getPosition()));
  84. return this;
  85. }
  86.  
  87. public int size() {
  88. - return list.size();
  89. + if (firstNode != null) {
  90. + if (list != null) {
  91. + return list.size() + 1;
  92. + } else {
  93. + return 1;
  94. + }
  95. + } else {
  96. + return 0;
  97. + }
  98. }
  99.  
  100.  
  101. @@ -108,7 +130,9 @@ public class ListNode extends Node {
  102. */
  103. public ListNode addAll(ListNode other) {
  104. if (other != null && other.size() > 0) {
  105. - list.addAll(other.list);
  106. + for (int i = 0; i < other.size(); i++) {
  107. + add(other.get(i));
  108. + }
  109.  
  110. setPosition(getPosition().union(getLast().getPosition()));
  111. }
  112. @@ -126,23 +150,47 @@ public class ListNode extends Node {
  113. }
  114.  
  115. public Node getLast() {
  116. - return list.size() == 0 ? null : list.get(list.size() - 1);
  117. + if (firstNode != null) {
  118. + if (list != null) {
  119. + return list.get(list.size() - 1);
  120. + } else {
  121. + return firstNode;
  122. + }
  123. + } else {
  124. + return null;
  125. + }
  126. }
  127.  
  128. public String toString() {
  129. String string = super.toString();
  130. StringBuilder b = new StringBuilder();
  131. - for (int i = 0; i < list.size(); i++) {
  132. - b.append(list.get(i));
  133. - if (i + 1 < list.size()) {
  134. - b.append(", ");
  135. + if (firstNode != null) {
  136. + b.append(firstNode);
  137. + if (list != null) {
  138. + for (Node n : list) {
  139. + b.append(", ");
  140. + b.append(n);
  141. + }
  142. }
  143. }
  144. return string + ": {" + b.toString() + "}";
  145. }
  146.  
  147. public List<Node> childNodes() {
  148. - return list;
  149. + if (firstNode != null) {
  150. + if (list != null) {
  151. + List newList = new ArrayList(list.size() + 1);
  152. + newList.add(firstNode);
  153. + newList.addAll(list);
  154. + return newList;
  155. + } else {
  156. + List newList = new ArrayList(1);
  157. + newList.add(firstNode);
  158. + return newList;
  159. + }
  160. + } else {
  161. + return Collections.emptyList();
  162. + }
  163. }
  164.  
  165. public Object accept(NodeVisitor visitor) {
  166. @@ -150,6 +198,12 @@ public class ListNode extends Node {
  167. }
  168.  
  169. public Node get(int idx) {
  170. - return list.get(idx);
  171. + if (idx == 0) {
  172. + return firstNode;
  173. + } else if (list != null) {
  174. + return list.get(idx - 1);
  175. + } else {
  176. + return null;
  177. + }
  178. }
  179. }
  180. diff --git a/src/org/jruby/javasupport/JavaClass.java b/src/org/jruby/javasupport/JavaClass.java
  181. index 63e4156..ea4f0b1 100644
  182. --- a/src/org/jruby/javasupport/JavaClass.java
  183. +++ b/src/org/jruby/javasupport/JavaClass.java
  184. @@ -247,7 +247,7 @@ public class JavaClass extends JavaObject {
  185. // called only by initializing thread; no synchronization required
  186. void addMethod(Method method, Class<?> javaClass) {
  187. if (methods == null) {
  188. - methods = new ArrayList<Method>();
  189. + methods = new ArrayList<Method>(4);
  190. }
  191. if (!Ruby.isSecurityRestricted()) {
  192. method.setAccessible(true);
  193. @@ -259,7 +259,7 @@ public class JavaClass extends JavaObject {
  194. // called only by initializing thread; no synchronization required
  195. void addAlias(String alias) {
  196. if (aliases == null) {
  197. - aliases = new ArrayList<String>();
  198. + aliases = new ArrayList<String>(4);
  199. }
  200. if (!aliases.contains(alias))
  201. aliases.add(alias);
  202. @@ -283,7 +283,7 @@ public class JavaClass extends JavaObject {
  203. // called only by initializing thread; no synchronization required
  204. void addConstructor(Constructor ctor, Class<?> javaClass) {
  205. if (constructors == null) {
  206. - constructors = new ArrayList<Constructor>();
  207. + constructors = new ArrayList<Constructor>(4);
  208. }
  209. if (!Ruby.isSecurityRestricted()) {
  210. ctor.setAccessible(true);
  211. @@ -624,31 +624,36 @@ public class JavaClass extends JavaObject {
  212. }
  213. }
  214.  
  215. - private void installClassConstructors(final RubyClass proxy) {
  216. + private synchronized void installClassConstructors(final RubyClass proxy) {
  217. if (constructorInstaller != null) {
  218. constructorInstaller.install(proxy);
  219. + constructorInstaller = null;
  220. }
  221. }
  222.  
  223. - private void installClassFields(final RubyClass proxy) {
  224. + private synchronized void installClassFields(final RubyClass proxy) {
  225. for (ConstantField field : constantFields) {
  226. field.install(proxy);
  227. }
  228. + constantFields = null;
  229. }
  230.  
  231. - private void installClassMethods(final RubyClass proxy) {
  232. + private synchronized void installClassMethods(final RubyClass proxy) {
  233. for (NamedInstaller installer : staticInstallers.values()) {
  234. if (installer.type == NamedInstaller.STATIC_METHOD && installer.hasLocalMethod()) {
  235. assignAliases((MethodInstaller) installer, staticAssignedNames);
  236. }
  237. installer.install(proxy);
  238. }
  239. + staticInstallers = null;
  240. +
  241. for (NamedInstaller installer : instanceInstallers.values()) {
  242. if (installer.type == NamedInstaller.INSTANCE_METHOD && installer.hasLocalMethod()) {
  243. assignAliases((MethodInstaller) installer, instanceAssignedNames);
  244. }
  245. installer.install(proxy);
  246. }
  247. + instanceInstallers = null;
  248. }
  249.  
  250. private void setupClassConstructors(Class<?> javaClass) {
Add Comment
Please, Sign In to add comment