Mercurial > hg > truffle
diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java @ 20023:cef214c6d74a
extract methods to avoid code duplication
author | Christian Wirth <christian.wirth@oracle.com> |
---|---|
date | Tue, 24 Mar 2015 17:33:15 +0100 |
parents | 94f16a759646 |
children |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java Tue Mar 24 17:19:23 2015 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java Tue Mar 24 17:33:15 2015 +0100 @@ -150,32 +150,27 @@ @Override public Object getValue(FrameSlot slot) { + int slotIndex = getSlotIndexChecked(slot); + return locals[slotIndex]; + } + + private int getSlotIndexChecked(FrameSlot slot) { int slotIndex = slot.getIndex(); if (slotIndex >= tags.length) { if (!resize()) { throw new IllegalArgumentException(String.format("The frame slot '%s' is not known by the frame descriptor.", slot)); } } - return locals[slotIndex]; + return slotIndex; } private void verifySet(FrameSlot slot, FrameSlotKind accessKind) { - int slotIndex = slot.getIndex(); - if (slotIndex >= tags.length) { - if (!resize()) { - throw new IllegalArgumentException(String.format("The frame slot '%s' is not known by the frame descriptor.", slot)); - } - } + int slotIndex = getSlotIndexChecked(slot); tags[slotIndex] = (byte) accessKind.ordinal(); } private void verifyGet(FrameSlot slot, FrameSlotKind accessKind) throws FrameSlotTypeException { - int slotIndex = slot.getIndex(); - if (slotIndex >= tags.length) { - if (!resize()) { - throw new IllegalArgumentException(String.format("The frame slot '%s' is not known by the frame descriptor.", slot)); - } - } + int slotIndex = getSlotIndexChecked(slot); byte tag = tags[slotIndex]; if (accessKind == FrameSlotKind.Object ? tag != 0 : tag != accessKind.ordinal()) { throw new FrameSlotTypeException(); @@ -195,12 +190,7 @@ } private byte getTag(FrameSlot slot) { - int slotIndex = slot.getIndex(); - if (slotIndex >= tags.length) { - if (!resize()) { - throw new IllegalArgumentException(String.format("The frame slot '%s' is not known by the frame descriptor.", slot)); - } - } + int slotIndex = getSlotIndexChecked(slot); return tags[slotIndex]; }