Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func parseMappings(mapsFile io.Reader) ([]Mapping, error) {
}
bufPool.Put(scanBuf)
}()

lastPath := ""
scanner.Buffer(*scanBuf, 8192)
for scanner.Scan() {
var fields [6]string
Expand Down Expand Up @@ -146,7 +148,14 @@ func parseMappings(mapsFile io.Reader) ([]Mapping, error) {
}
} else {
path = trimMappingPath(path)
path = strings.Clone(path)
if path == lastPath {
// Take advantage of the fact that mappings are sorted by path
// and avoid allocating the same string multiple times.
path = lastPath
} else {
Comment on lines +151 to +155
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we skip the assignment of path = lastPath if path == lastPath?

Suggested change
if path == lastPath {
// Take advantage of the fact that mappings are sorted by path
// and avoid allocating the same string multiple times.
path = lastPath
} else {
if path != lastPath {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we skip the assignment of path = lastPath if path == lastPath?

No, this is exactly where the de-duplication happens.
path == lastPath compares the string content, and here both contents are at different memory locations. So if the contents are the same, the path = lastPath changes the memory location of path to the already existing lastPath.

path = strings.Clone(path)
lastPath = path
}
}

vaddr := util.HexToUint64(addrs[0])
Expand Down