Ignore:
Timestamp:
2023-10-03T16:25:42+02:00 (18 months ago)
Author:
taylor.smock
Message:

Fix #23212: Overpass query wizard should transform key: to ["key"] instead of [~"key"~""]

This is fixed by using ExactKeyValue instead of KeyValue for key: queries.
As a happy side effect, this significantly reduces the cost of key: queries.
In a test area ("Mesa County, Colorado"), this reduces the cpu time from 2600ms
to 200ms and reduces memory allocations from 425mb to effectively 0 for a name:
query.

In addition, this simplifies many equals methods by converting the following
pattern to Objects.equals(first, second):

if (first == null) {
    if (second != null) {
        return true;
    }
} else if (!first.equals(second))
    return false;
return true;

There are some additional changes, mostly related to documentation and lint
issues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/SearchCompilerQueryWizard.java

    r17988 r18847  
    3838    public static String constructQuery(final String search) {
    3939        try {
    40             Matcher matcher = Pattern.compile("\\s+GLOBAL\\s*$", Pattern.CASE_INSENSITIVE).matcher(search);
     40            Matcher matcher = Pattern.compile("\\s+GLOBAL\\s*$", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CHARACTER_CLASS)
     41                    .matcher(search);
    4142            if (matcher.find()) {
    4243                final Match match = SearchCompiler.compile(matcher.replaceFirst(""));
     
    4445            }
    4546
    46             matcher = Pattern.compile("\\s+IN BBOX\\s*$", Pattern.CASE_INSENSITIVE).matcher(search);
     47            matcher = Pattern.compile("\\s+IN BBOX\\s*$", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CHARACTER_CLASS)
     48                    .matcher(search);
    4749            if (matcher.find()) {
    4850                final Match match = SearchCompiler.compile(matcher.replaceFirst(""));
     
    5052            }
    5153
    52             matcher = Pattern.compile("\\s+(?<mode>IN|AROUND)\\s+(?<area>[^\" ]+|\"[^\"]+\")\\s*$", Pattern.CASE_INSENSITIVE).matcher(search);
     54            matcher = Pattern.compile("\\s+(?<mode>IN|AROUND)\\s+(?<area>[^\" ]+|\"[^\"]+\")\\s*$",
     55                    Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CHARACTER_CLASS).matcher(search);
    5356            if (matcher.find()) {
    5457                final Match match = SearchCompiler.compile(matcher.replaceFirst(""));
     
    7982            final EnumSet<OsmPrimitiveType> types = EnumSet.noneOf(OsmPrimitiveType.class);
    8083            final String query = constructQuery(conjunction, types);
    81             (types.isEmpty() || types.size() == 3
     84            queryLines.addAll((types.isEmpty() || types.size() == 3
    8285                    ? Stream.of("nwr")
    8386                    : types.stream().map(OsmPrimitiveType::getAPIName))
    84                     .forEach(type -> queryLines.add("  " + type + query + queryLineSuffix + ";"));
     87                    .map(type -> "  " + type + query + queryLineSuffix + ";")
     88                    .collect(Collectors.toList()));
    8589        }
    8690        queryLines.add(");");
Note: See TracChangeset for help on using the changeset viewer.