mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-05-25 20:17:45 +00:00
#1240 JPEXS does not use multiple threads for decompilation on Text Search: AS2 is also multi thread now, work status improvements during search
This commit is contained in:
@@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedText;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
|
||||
import com.jpexs.decompiler.flash.tags.base.ASMSource;
|
||||
import com.jpexs.helpers.ImmediateFuture;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -51,10 +52,13 @@ public class DecompilerPool {
|
||||
}
|
||||
|
||||
public Future<HighlightedText> submitTask(ASMSource src, ActionList actions, ScriptDecompiledListener<HighlightedText> listener) {
|
||||
Future<HighlightedText> f = executor.submit(new Callable<HighlightedText>() {
|
||||
Callable<HighlightedText> callable = new Callable<HighlightedText>() {
|
||||
@Override
|
||||
public HighlightedText call() throws Exception {
|
||||
Thread.sleep(10000);
|
||||
if (listener != null) {
|
||||
listener.onStart();
|
||||
}
|
||||
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
|
||||
writer.startFunction("!script");
|
||||
src.getActionScriptSource(writer, actions);
|
||||
@@ -72,22 +76,25 @@ public class DecompilerPool {
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return f;
|
||||
return submit(callable);
|
||||
}
|
||||
|
||||
public Future<HighlightedText> submitTask(ScriptPack pack, ScriptDecompiledListener<HighlightedText> listener) {
|
||||
Future<HighlightedText> f = executor.submit(new Callable<HighlightedText>() {
|
||||
Callable<HighlightedText> callable = new Callable<HighlightedText>() {
|
||||
@Override
|
||||
public HighlightedText call() throws Exception {
|
||||
if (listener != null) {
|
||||
listener.onStart();
|
||||
}
|
||||
|
||||
int scriptIndex = pack.scriptIndex;
|
||||
ScriptInfo script = null;
|
||||
if (scriptIndex > -1) {
|
||||
script = pack.abc.script_info.get(scriptIndex);
|
||||
}
|
||||
boolean parallel = Configuration.parallelSpeedUp.get();
|
||||
Thread.sleep(10000);
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
|
||||
pack.toSource(writer, script == null ? null : script.traits.traits, new ConvertData(), ScriptExportMode.AS, parallel);
|
||||
|
||||
@@ -103,9 +110,30 @@ public class DecompilerPool {
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return f;
|
||||
return submit(callable);
|
||||
}
|
||||
|
||||
private Future<HighlightedText> submit(Callable<HighlightedText> callable) {
|
||||
boolean parallel = Configuration.parallelSpeedUp.get();
|
||||
if (parallel) {
|
||||
Future<HighlightedText> f = executor.submit(callable);
|
||||
return f;
|
||||
} else {
|
||||
boolean cancelled = false;
|
||||
Throwable throwable = null;
|
||||
HighlightedText result = null;
|
||||
try {
|
||||
result = callable.call();
|
||||
} catch (InterruptedException ex) {
|
||||
cancelled = true;
|
||||
} catch (Exception ex) {
|
||||
throwable = ex;
|
||||
}
|
||||
|
||||
return new ImmediateFuture<>(result, throwable, cancelled);
|
||||
}
|
||||
}
|
||||
|
||||
public String getStat() {
|
||||
|
||||
@@ -2958,8 +2958,7 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
timelined.setModified(true);
|
||||
timelined.resetTimeline();
|
||||
} else // timeline should be always the swf here
|
||||
{
|
||||
if (removeDependencies) {
|
||||
if (removeDependencies) {
|
||||
removeTagWithDependenciesFromTimeline(tag, timelined.getTimeline());
|
||||
timelined.setModified(true);
|
||||
} else {
|
||||
@@ -2968,7 +2967,6 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
timelined.setModified(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,8 +20,9 @@ package com.jpexs.decompiler.flash.cache;
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ScriptDecompiledListener<T> {
|
||||
|
||||
public void onStart();
|
||||
|
||||
public void onComplete(T result);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2016 JPEXS, All rights reserved.
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.helpers;
|
||||
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -29,8 +31,20 @@ public class ImmediateFuture<V> implements Future<V> {
|
||||
|
||||
private final V value;
|
||||
|
||||
private final Throwable throwable;
|
||||
|
||||
private final boolean cancelled;
|
||||
|
||||
public ImmediateFuture(V value) {
|
||||
this.value = value;
|
||||
throwable = null;
|
||||
cancelled = false;
|
||||
}
|
||||
|
||||
public ImmediateFuture(V value, Throwable throwable, boolean cancelled) {
|
||||
this.value = value;
|
||||
this.throwable = throwable;
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,7 +54,7 @@ public class ImmediateFuture<V> implements Future<V> {
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,11 +64,19 @@ public class ImmediateFuture<V> implements Future<V> {
|
||||
|
||||
@Override
|
||||
public V get() throws InterruptedException, ExecutionException {
|
||||
if (cancelled) {
|
||||
throw new CancellationException();
|
||||
}
|
||||
|
||||
if (throwable != null) {
|
||||
throw new ExecutionException(throwable);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
return get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user