Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(#3790): fixed AtWithRho performance problems + not set rho to lambda #3803

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions eo-runtime/src/main/java/org/eolang/Action.java

This file was deleted.

2 changes: 1 addition & 1 deletion eo-runtime/src/main/java/org/eolang/AtComposite.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Phi get() {
}

@Override
public boolean put(final Phi phi) {
public void put(final Phi phi) {
throw new ExReadOnly(
"Can't overwrite lambda expression"
);
Expand Down
5 changes: 2 additions & 3 deletions eo-runtime/src/main/java/org/eolang/AtLogged.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ public Phi get() {
}

@Override
public boolean put(final Phi src) {
public void put(final Phi src) {
this.log.info(String.format(" %s.put()...\n", this.owner));
final boolean ret = this.origin.put(src);
this.origin.put(src);
this.log.info(String.format(" %s.put()!\n", this.owner));
return ret;
}
}
3 changes: 1 addition & 2 deletions eo-runtime/src/main/java/org/eolang/AtOnce.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ public Phi get() {
}

@Override
public boolean put(final Phi phi) {
public void put(final Phi phi) {
throw new ExReadOnly(
String.format(
"Can't overwrite the \"%s\" attribute",
this.origin
)
);
}

}
7 changes: 1 addition & 6 deletions eo-runtime/src/main/java/org/eolang/AtRho.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,9 @@ public Phi get() {
}

@Override
public boolean put(final Phi phi) {
final boolean ret;
public void put(final Phi phi) {
if (this.rho.get() == null) {
this.rho.set(phi);
ret = true;
} else {
ret = false;
}
return ret;
}
}
57 changes: 0 additions & 57 deletions eo-runtime/src/main/java/org/eolang/AtSetRho.java

This file was deleted.

4 changes: 1 addition & 3 deletions eo-runtime/src/main/java/org/eolang/AtVoid.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Phi get() {
}

@Override
public boolean put(final Phi phi) {
public void put(final Phi phi) {
if (this.object.get() == null) {
this.object.set(phi);
} else {
Expand All @@ -100,7 +100,5 @@ public boolean put(final Phi phi) {
)
);
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,51 @@

package org.eolang;

import java.util.function.Supplier;

/**
* Attribute that only gets objects.
*
* The attribute that tries to copy object and set \rho to it if it has not already set.
* @since 0.36.0
*/
final class AtGetOnly implements Attr {
final class AtWithRho implements Attr {
/**
* Original attribute.
*/
private final Attr origin;

/**
* Get object supplier.
* Rho.
*/
private final Supplier<Phi> function;
private final Phi rho;

/**
* Ctor.
* @param func Get object function
* @param attr Attribute
* @param rho Rho
*/
AtGetOnly(final Supplier<Phi> func) {
this.function = func;
AtWithRho(final Attr attr, final Phi rho) {
this.origin = attr;
this.rho = rho;
}

@Override
public Attr copy(final Phi self) {
throw new UnsupportedOperationException(
"Should never happen"
return new AtWithRho(
this.origin.copy(self),
self
);
}

@Override
public Phi get() {
return this.function.get();
Phi ret = this.origin.get();
if (!ret.hasRho()) {
ret = ret.copy();
ret.put(Attr.RHO, this.rho);
}
return ret;
}

@Override
public boolean put(final Phi phi) {
throw new UnsupportedOperationException(
"Should never happen"
);
public void put(final Phi phi) {
this.origin.put(phi);
}
}
6 changes: 3 additions & 3 deletions eo-runtime/src/main/java/org/eolang/AtomSafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public final class AtomSafe implements Atom {

/**
* Ctor.
* @param atom Original atom.
* @param atom Phi as atom.
*/
public AtomSafe(final Atom atom) {
this.origin = atom;
public AtomSafe(final Phi atom) {
this.origin = (Atom) atom;
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions eo-runtime/src/main/java/org/eolang/Attr.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public interface Attr {
/**
* Take the object out.
*
* <p>If attribute is not set - throws {@link ExUnset}.</p>
*
* @return The object
*/
Phi get();
Expand All @@ -64,7 +66,6 @@ public interface Attr {
* Put a new object in.
*
* @param phi The object to put
* @return Was attribute set
*/
boolean put(Phi phi);
void put(Phi phi);
}
13 changes: 9 additions & 4 deletions eo-runtime/src/main/java/org/eolang/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,24 @@ public Phi copy() {
return this.object.copy();
}

@Override
public boolean hasRho() {
return this.object.hasRho();
}

@Override
public Phi take(final String name) {
return this.object.take(name);
}

@Override
public boolean put(final int pos, final Phi obj) {
return this.object.put(pos, obj);
public void put(final int pos, final Phi obj) {
this.object.put(pos, obj);
}

@Override
public boolean put(final String name, final Phi obj) {
return this.object.put(name, obj);
public void put(final String name, final Phi obj) {
this.object.put(name, obj);
}

@Override
Expand Down
Loading
Loading