Commit c987483
committed
[jcwgen] add public method for GetDestinationPath (#402)
Context: dotnet/android#2505 (comment)
Xamarin.Android is working to reduce the number of temporary files
which are generated during the build, in order to improve build time.
We would like `JavaCallableWrapperGenerator` to assist in that effort.
Currently we are doing:
// jti is a JavaCallableWrapperGenerator instance
jti.Generate (outputPath);
// Then later in our MSBuild task
foreach (var file in Directory.GetFiles (temp, "*", SearchOption.AllDirectories)) {
...
MonoAndroidHelper.CopyIfChanged (file, dest);
}
This is slower than it could be:
1. Writes to a bunch of temp files.
2. Recurses the directory where all these temp files exist.
3. Does a hash comparison of the contents of the source and
destination.
4. Copies the file if needed.
5. Deletes all the temp files.
Instead, we want to instead do:
using (var memoryStream = new MemoryStream ())
using (var writer = new StreamWriter (memoryStream)) {
jti.Generate (writer);
writer.Flush ();
var path = jti.GetDestinationPath (outputPath);
MonoAndroidHelper.CopyIfStreamChanged (memoryStream, path);
}
This is more streamlined:
1. Generate the file in-memory.
2. Do a hash comparison of the in-memory file vs. the destination.
3. Write to the file if needed.
The change we need in Java.Interop here is to add the
`JavaCallableWrapperGenerator.GetDestinationPath()` method. Further
changes downstream in xamarin-android will allow us reap the benefits.
I also improved the code a bit, no longer using `string.Split()`.
We can do a simple `string.Replace()` from `.` to
`Path.DirectorySeparatorChar`, which allocates fewer strings.1 parent 6c5b4ea commit c987483
File tree
1 file changed
+11
-8
lines changed- src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers
1 file changed
+11
-8
lines changedLines changed: 11 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
856 | 856 | | |
857 | 857 | | |
858 | 858 | | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
865 | 863 | | |
866 | | - | |
867 | | - | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
868 | 871 | | |
869 | 872 | | |
870 | 873 | | |
| |||
0 commit comments