Skip to content

Commit

Permalink
Improve performance and memory by caching XML Schema / DTD
Browse files Browse the repository at this point in the history
Fixes #534

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Oct 9, 2019
1 parent 802ce50 commit 22ae728
Show file tree
Hide file tree
Showing 4 changed files with 470 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.eclipse.lsp4xml.extensions.contentmodel.model;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
import java.util.logging.Level;
import java.util.logging.Logger;

public class FileChangedTracker {

private static final Logger LOGGER = Logger.getLogger(FileChangedTracker.class.getName());

private final Path file;
private FileTime lastModified;

public FileChangedTracker(Path file) {
this.file = file;
try {
lastModified = Files.getLastModifiedTime(file);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Get last modified time failed", e);
}
}

public boolean isDirty() {
try {
if (!Files.exists(file)) {
// This case occurs when user delete the XML Schema / DTD file
return true;
}
FileTime currentLastMofied = Files.getLastModifiedTime(file);
if (!currentLastMofied.equals(lastModified)) {
lastModified = currentLastMofied;
return true;
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Get last modified time failed", e);
return true;
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
*******************************************************************************/
package org.eclipse.lsp4xml.extensions.contentmodel.model;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
Expand All @@ -31,40 +27,6 @@ public class FilesChangedTracker {

private static final Logger LOGGER = Logger.getLogger(FilesChangedTracker.class.getName());

private static class FileChangedTracker {

private final Path file;
private FileTime lastModified;

public FileChangedTracker(Path file) {
this.file = file;
try {
lastModified = Files.getLastModifiedTime(file);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Get last modified time failed", e);
}
}

public boolean isDirty() {
try {
if (!Files.exists(file)) {
// This case occurs when user delete the XML Schema / DTD file
return true;
}
FileTime currentLastMofied = Files.getLastModifiedTime(file);
if (!currentLastMofied.equals(lastModified)) {
lastModified = currentLastMofied;
return true;
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Get last modified time failed", e);
return true;
}
return false;
}

}

private final List<FileChangedTracker> files;

public FilesChangedTracker() {
Expand Down
Loading

0 comments on commit 22ae728

Please sign in to comment.