Highlighter - faster typing (timer delay),

sort optimization
This commit is contained in:
Jindra Petřík
2025-06-15 19:20:09 +02:00
parent aecef68d7b
commit 66ca60bed2
11 changed files with 99 additions and 80 deletions

View File

@@ -25,28 +25,23 @@ import java.util.List;
*/
public class CatchScope implements Scope {
private final List<VariableOrScope> privateItems;
private final List<VariableOrScope> sharedItems;
private final List<VariableOrScopeWithAccess> items = new ArrayList<>();
private final int position;
private final int endPosition;
public CatchScope(int position, int endPosition, Variable catchVariable, List<VariableOrScope> catchBody) {
this.privateItems = new ArrayList<>();
this.privateItems.add(catchVariable);
this.sharedItems = catchBody;
items.add(new VariableOrScopeWithAccess(catchVariable, false));
for (VariableOrScope s : catchBody) {
items.add(new VariableOrScopeWithAccess(s, true));
}
this.position = position;
this.endPosition = endPosition;
}
@Override
public List<VariableOrScope> getSharedItems() {
return sharedItems;
}
@Override
public List<VariableOrScope> getPrivateItems() {
return privateItems;
}
public List<VariableOrScopeWithAccess> getScopeItems() {
return items;
}
@Override
public int getPosition() {

View File

@@ -25,25 +25,22 @@ import java.util.List;
*/
public class ClassScope implements Scope {
private final List<VariableOrScope> privateItems;
private final List<VariableOrScopeWithAccess> items = new ArrayList<>();
private final int position;
private final int endPosition;
public ClassScope(int position, int endPosition, List<VariableOrScope> traits) {
this.privateItems = traits;
for (VariableOrScope s : traits) {
items.add(new VariableOrScopeWithAccess(s, false));
}
this.position = position;
this.endPosition = endPosition;
}
@Override
public List<VariableOrScope> getSharedItems() {
return new ArrayList<>();
}
@Override
public List<VariableOrScope> getPrivateItems() {
return privateItems;
}
public List<VariableOrScopeWithAccess> getScopeItems() {
return items;
}
@Override
public int getPosition() {

View File

@@ -25,13 +25,15 @@ import java.util.List;
*/
public class FunctionScope implements Scope {
private final List<VariableOrScope> privateItems;
private final List<VariableOrScopeWithAccess> items = new ArrayList<>();
private final boolean isStatic;
private final int position;
private final int endPosition;
public FunctionScope(int position, int endPosition, List<VariableOrScope> functionBody, boolean isStatic) {
this.privateItems = functionBody;
for (VariableOrScope s : functionBody) {
items.add(new VariableOrScopeWithAccess(s, false));
}
this.isStatic = isStatic;
this.position = position;
this.endPosition = endPosition;
@@ -41,15 +43,6 @@ public class FunctionScope implements Scope {
return isStatic;
}
@Override
public List<VariableOrScope> getSharedItems() {
return new ArrayList<>();
}
@Override
public List<VariableOrScope> getPrivateItems() {
return privateItems;
}
@Override
public int getPosition() {
@@ -60,5 +53,10 @@ public class FunctionScope implements Scope {
public int getEndPosition() {
return endPosition;
}
@Override
public List<VariableOrScopeWithAccess> getScopeItems() {
return items;
}
}

View File

@@ -32,6 +32,8 @@ public class Path {
public static Path PATH_PARENTHESIS = new Path(PART_PARENTHESIS);
public static Path PATH_BRACKETS = new Path(PART_BRACKETS);
private Integer cachedHashCode = null;
@Override
public String toString() {
@@ -133,9 +135,12 @@ public class Path {
@Override
public int hashCode() {
if (cachedHashCode != null) {
return cachedHashCode;
}
int hash = 5;
hash = 89 * hash + Objects.hashCode(this.parts);
return hash;
return cachedHashCode = hash;
}
@Override

View File

@@ -24,9 +24,7 @@ import java.util.List;
*/
public interface Scope extends VariableOrScope {
public List<VariableOrScope> getSharedItems();
public List<VariableOrScope> getPrivateItems();
public List<VariableOrScopeWithAccess> getScopeItems();
public int getEndPosition();
}

View File

@@ -314,21 +314,8 @@ public interface SimpleParser {
}
}
}
List<VariableOrScopeWithAccess> list = new ArrayList<>();
for (VariableOrScope it : vs.getPrivateItems()) {
list.add(new VariableOrScopeWithAccess(it, false));
}
for (VariableOrScope it : vs.getSharedItems()) {
list.add(new VariableOrScopeWithAccess(it, true));
}
list.sort(new Comparator<VariableOrScopeWithAccess>() {
@Override
public int compare(VariableOrScopeWithAccess o1, VariableOrScopeWithAccess o2) {
return o1.var.getPosition() - o2.var.getPosition();
}
});
parseVariablesList(list, definitionPosToReferences, referenceToDefinition, privateVarFullNameToDefinitionPosition, privateVarNameToDefinitionPosition, positionToStatic, subStatic, errors, vs, innerFunctionCanUseTraits, externalSimpleTypes, externalFullTypes, referenceToExternalTypeIndex, definitionToType, definitionToCallType, definitionToSubType, definitionToCallSubType, traitFullNameToDefinition, linkHandler, simpleExternalClassNameToFullClassName, referenceToExternalTraitKey, externalTraitKeyToReference, separatorPosToType, separatorIsStatic, caretPosition, variableSuggestions, vs.getPosition(), vs.getEndPosition());
parseVariablesList(vs.getScopeItems(), definitionPosToReferences, referenceToDefinition, privateVarFullNameToDefinitionPosition, privateVarNameToDefinitionPosition, positionToStatic, subStatic, errors, vs, innerFunctionCanUseTraits, externalSimpleTypes, externalFullTypes, referenceToExternalTypeIndex, definitionToType, definitionToCallType, definitionToSubType, definitionToCallSubType, traitFullNameToDefinition, linkHandler, simpleExternalClassNameToFullClassName, referenceToExternalTraitKey, externalTraitKeyToReference, separatorPosToType, separatorIsStatic, caretPosition, variableSuggestions, vs.getPosition(), vs.getEndPosition());
}
if (vt2 != null && caretPosition != null && variableSuggestions.isEmpty()) {
@@ -409,15 +396,8 @@ public interface SimpleParser {
parentVarNameToDefinitionPosition.put(ct.getLastName(), ct.position);
}
if (v instanceof Scope) {
Scope s = (Scope) v;
List<VariableOrScopeWithAccess> list = new ArrayList<>();
for (VariableOrScope it : s.getPrivateItems()) {
list.add(new VariableOrScopeWithAccess(it, false));
}
for (VariableOrScope it : s.getSharedItems()) {
list.add(new VariableOrScopeWithAccess(it, true));
}
findClassTraits(list, traitFullNameToDefinition, definitionPosToReferences, positionToStatic, definitionToType, definitionToCallType, definitionToSubType, definitionToCallSubType, parentVarFullNameToDefinitionPosition, parentVarNameToDefinitionPosition);
Scope s = (Scope) v;
findClassTraits(s.getScopeItems(), traitFullNameToDefinition, definitionPosToReferences, positionToStatic, definitionToType, definitionToCallType, definitionToSubType, definitionToCallSubType, parentVarFullNameToDefinitionPosition, parentVarNameToDefinitionPosition);
}
}
}

View File

@@ -28,30 +28,22 @@ public class TraitVarConstValueScope implements Scope {
private final int position;
private final int endPosition;
private List<VariableOrScope> sharedItems;
private final List<VariableOrScopeWithAccess> items = new ArrayList<>();
private final boolean isStatic;
public TraitVarConstValueScope(int position, int endPosition, List<VariableOrScope> sharedItems, boolean isStatic) {
this.position = position;
this.endPosition = endPosition;
this.sharedItems = sharedItems;
for (VariableOrScope s : sharedItems) {
items.add(new VariableOrScopeWithAccess(s, true));
}
this.isStatic = isStatic;
}
public boolean isStatic() {
return isStatic;
}
@Override
public List<VariableOrScope> getSharedItems() {
return sharedItems;
}
@Override
public List<VariableOrScope> getPrivateItems() {
return new ArrayList<>();
}
@Override
public int getPosition() {
return position;
@@ -61,6 +53,11 @@ public class TraitVarConstValueScope implements Scope {
public int getEndPosition() {
return endPosition;
}
@Override
public List<VariableOrScopeWithAccess> getScopeItems() {
return items;
}
}

View File

@@ -255,6 +255,18 @@ public class DottedChain implements Serializable, Comparable<DottedChain> {
return parts.get(index).name;
}
/**
* Gets string parts as list.
* @return String parts
*/
public List<String> getStringParts() {
List<String> ret = new ArrayList<>();
for (int i = 0; i < parts.size(); i++) {
ret.add(parts.get(i).name);
}
return ret;
}
/**
* Checks whether the part at the given index is an attribute.

View File

@@ -1779,5 +1779,17 @@ public class Helper {
}
return Integer.parseInt(version);
}
public static List<String> splitString(String delimiter, String str) {
List<String> result = new ArrayList<>();
int start = 0;
int end;
while ((end = str.indexOf(delimiter, start)) != -1) {
result.add(str.substring(start, end));
start = end + 1;
}
result.add(str.substring(start));
return result;
}
}