Unverified Commit cc737536 authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

Fix library-cache-miss regression (#433)

* Fixed library-cache-miss regression

* Changed 'includeCacheEntry' field to pointer type

This allows a better memory management and avoids struct copy
operations.
parent 3dcbb9bb
......@@ -108,6 +108,7 @@ package builder
import (
"encoding/json"
"fmt"
"os"
"os/exec"
"time"
......@@ -196,19 +197,28 @@ 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
}
// 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]
}
......@@ -227,9 +237,9 @@ 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() == entry {
if cache.next < len(cache.entries) && cache.Next().Equals(entry) {
cache.next++
} else {
cache.valid = false
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment