Remove SourcePath.srcDir
This was always set to "." after aosp/1652613 and
aosp/1796650. While doing some rudimentary performance
profiling of soong, it turned out that SourcePath.String()
was taking 600+MB of memory joining the "." to the rest
of the path. Remove it for performance gains.
Bug: 262629589
Test: Verfied ninja files didn't change with this cl on aosp_arm64-userdebug
Change-Id: Id6b552ab8defe37e0c2b58e813fb1dbae427ae96
diff --git a/android/paths.go b/android/paths.go
index a6a54fa..0fc39df 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -1033,9 +1033,6 @@
// SourcePath is a Path representing a file path rooted from SrcDir
type SourcePath struct {
basePath
-
- // The sources root, i.e. Config.SrcDir()
- srcDir string
}
func (p SourcePath) RelativeToTop() Path {
@@ -1054,7 +1051,7 @@
// code that is embedding ninja variables in paths
func safePathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
p, err := validateSafePath(pathComponents...)
- ret := SourcePath{basePath{p, ""}, "."}
+ ret := SourcePath{basePath{p, ""}}
if err != nil {
return ret, err
}
@@ -1071,7 +1068,7 @@
// pathForSource creates a SourcePath from pathComponents, but does not check that it exists.
func pathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
p, err := validatePath(pathComponents...)
- ret := SourcePath{basePath{p, ""}, "."}
+ ret := SourcePath{basePath{p, ""}}
if err != nil {
return ret, err
}
@@ -1174,7 +1171,10 @@
}
func (p SourcePath) String() string {
- return filepath.Join(p.srcDir, p.path)
+ if p.path == "" {
+ return "."
+ }
+ return p.path
}
// Join creates a new SourcePath with paths... joined with the current path. The
@@ -1207,7 +1207,7 @@
// No need to put the error message into the returned path since it has been reported already.
return OptionalPath{}
}
- dir := filepath.Join(p.srcDir, p.path, relDir)
+ dir := filepath.Join(p.path, relDir)
// Use Glob so that we are run again if the directory is added.
if pathtools.IsGlob(dir) {
ReportPathErrorf(ctx, "Path may not contain a glob: %s", dir)
@@ -1220,8 +1220,7 @@
if len(paths) == 0 {
return InvalidOptionalPath(dir + " does not exist")
}
- relPath := Rel(ctx, p.srcDir, paths[0])
- return OptionalPathForPath(PathForSource(ctx, relPath))
+ return OptionalPathForPath(PathForSource(ctx, paths[0]))
}
// OutputPath is a Path representing an intermediates file path rooted from the build directory