Skip to content

Commit

Permalink
Revert "Use streams to build these collections"
Browse files Browse the repository at this point in the history
This reverts commit 2b9ca74.
  • Loading branch information
headius committed May 25, 2024
1 parent 5d65f33 commit 28a35fd
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -1364,25 +1363,29 @@ public List<Variable<Object>> getVariableList() {
* @see IRubyObject#getMarshalVariableList()
*/
public List<Variable<Object>> getMarshalVariableList() {
return metaClass.getVariableAccessorsForRead()
.entrySet()
.stream()
.map(entry -> (Variable<Object>) new VariableEntry<>(entry.getKey(), entry.getValue().get(this)))
.filter(var -> var.getValue() != null && var.getValue() instanceof Serializable)
.toList();
Map<String, VariableAccessor> ivarAccessors = metaClass.getVariableAccessorsForRead();
ArrayList<Variable<Object>> list = new ArrayList<>(ivarAccessors.size());
for (Map.Entry<String, VariableAccessor> entry : ivarAccessors.entrySet()) {
Object value = entry.getValue().get(this);
if (value == null || !(value instanceof Serializable)) continue;
list.add(new VariableEntry<>(entry.getKey(), value));
}
return list;
}

/**
* Gets a name list of all variables in this object.
*/
@Override
public List<String> getVariableNameList() {
return metaClass.getVariableAccessorsForRead()
.entrySet()
.stream()
.filter(entry -> entry.getValue().get(this) != null)
.map(entry -> entry.getKey())
.toList();
Map<String, VariableAccessor> ivarAccessors = metaClass.getVariableAccessorsForRead();
ArrayList<String> list = new ArrayList<>(ivarAccessors.size());
for (Map.Entry<String, VariableAccessor> entry : ivarAccessors.entrySet()) {
Object value = entry.getValue().get(this);
if (value == null) continue;
list.add(entry.getKey());
}
return list;
}

/**
Expand Down

0 comments on commit 28a35fd

Please sign in to comment.