From 3d7a9e1a41cd34f05460bb8800aa2e6ec4e6d5dc Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 1 Oct 2019 13:28:44 +0200 Subject: [PATCH 1/2] Fixed library-cache-miss regression --- legacy/builder/container_find_includes.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/legacy/builder/container_find_includes.go b/legacy/builder/container_find_includes.go index 5666676c902..d0aca20c677 100644 --- a/legacy/builder/container_find_includes.go +++ b/legacy/builder/container_find_includes.go @@ -108,6 +108,7 @@ package builder import ( "encoding/json" + "fmt" "os" "os/exec" "time" @@ -196,13 +197,22 @@ type includeCacheEntry struct { Includepath *paths.Path } +func (entry includeCacheEntry) String() string { + return fmt.Sprintf("SourceFile: %s; Include: %s; IncludePath: %s", + entry.Sourcefile, entry.Include, entry.Includepath) +} + +func (entry includeCacheEntry) Equals(other includeCacheEntry) bool { + return entry.String() == other.String() +} + type includeCache struct { // Are the cache contents valid so far? valid bool // Index into entries of the next entry to be processed. Unused // when the cache is invalid. next int - entries []includeCacheEntry + entries []includeCacheEntry // XXX: Convert to pointers } // Return the next cache entry. Should only be called when the cache is @@ -229,7 +239,7 @@ func (cache *includeCache) ExpectFile(sourcefile *paths.Path) { func (cache *includeCache) ExpectEntry(sourcefile *paths.Path, include string, librarypath *paths.Path) { entry := includeCacheEntry{Sourcefile: sourcefile, Include: include, Includepath: librarypath} if cache.valid { - if cache.next < len(cache.entries) && cache.Next() == entry { + if cache.next < len(cache.entries) && cache.Next().Equals(entry) { cache.next++ } else { cache.valid = false From 5f7b54a14051af5f21c0f85b862c9a9d9cc10590 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 1 Oct 2019 13:34:30 +0200 Subject: [PATCH 2/2] Changed 'includeCacheEntry' field to pointer type This allows a better memory management and avoids struct copy operations. --- legacy/builder/container_find_includes.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/legacy/builder/container_find_includes.go b/legacy/builder/container_find_includes.go index d0aca20c677..d7c0f90ed25 100644 --- a/legacy/builder/container_find_includes.go +++ b/legacy/builder/container_find_includes.go @@ -197,12 +197,12 @@ type includeCacheEntry struct { Includepath *paths.Path } -func (entry includeCacheEntry) String() string { +func (entry *includeCacheEntry) String() string { return fmt.Sprintf("SourceFile: %s; Include: %s; IncludePath: %s", entry.Sourcefile, entry.Include, entry.Includepath) } -func (entry includeCacheEntry) Equals(other includeCacheEntry) bool { +func (entry *includeCacheEntry) Equals(other *includeCacheEntry) bool { return entry.String() == other.String() } @@ -212,13 +212,13 @@ type includeCache struct { // Index into entries of the next entry to be processed. Unused // when the cache is invalid. next int - entries []includeCacheEntry // XXX: Convert to pointers + entries []*includeCacheEntry } // Return the next cache entry. Should only be called when the cache is // valid and a next entry is available (the latter can be checked with // ExpectFile). Does not advance the cache. -func (cache *includeCache) Next() includeCacheEntry { +func (cache *includeCache) Next() *includeCacheEntry { return cache.entries[cache.next] } @@ -237,7 +237,7 @@ func (cache *includeCache) ExpectFile(sourcefile *paths.Path) { // invalidated, or was already invalid, an entry with the given values // is appended. func (cache *includeCache) ExpectEntry(sourcefile *paths.Path, include string, librarypath *paths.Path) { - entry := includeCacheEntry{Sourcefile: sourcefile, Include: include, Includepath: librarypath} + entry := &includeCacheEntry{Sourcefile: sourcefile, Include: include, Includepath: librarypath} if cache.valid { if cache.next < len(cache.entries) && cache.Next().Equals(entry) { cache.next++