Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of restxml_unmarshal #762

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion paws.common/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: paws.common
Type: Package
Title: Paws Low-Level Amazon Web Services API
Version: 0.7.1
Version: 0.7.1.9000
Authors@R: c(
person("David", "Kretch", email = "[email protected]", role = "aut"),
person("Adam", "Banker", email = "[email protected]", role = "aut"),
Expand Down
3 changes: 3 additions & 0 deletions paws.common/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# paws.common 0.7.1.9000
* improve performance of `restxml_unmarshal` by x3

# paws.common 0.7.1
* minor performance enhancements
* fix MIME type for AWS BedrockRuntime Client (#749), thanks to @alex23lemm for raising issue.
Expand Down
41 changes: 4 additions & 37 deletions paws.common/R/xmlutil.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ xml_parse_structure <- function(xml_elts, interface_i, tags_i, tag_type = NULL,

# the `is.list()` check is necessary because e.g. `CheckSumAlgorithm` has
# a list interface though it isn't a list?!
if (isTRUE(flattened)) {
result <- transpose(result)
if (isTRUE(flattened) && is.list(result)) {
result <- .mapply(list, result, NULL)
} else {
result <- as.list(result)
}
Expand Down Expand Up @@ -357,8 +357,8 @@ xml_parse_list <- function(xml_elts, interface_i, tags_i, tag_type = NULL, flatt

# the `is.list()` check is necessary because e.g. `CheckSumAlgorithm` has
# a list interface though it isn't a list?!
if (isTRUE(flattened)) {
result <- transpose(result)
if (isTRUE(flattened) && is.list(result)) {
result <- .mapply(list, result, NULL)
}

return(result)
Expand Down Expand Up @@ -460,36 +460,3 @@ default_parse_scalar <- function(interface_i, tag_type = NULL) {
)
return(result)
}

transpose <- function(x) {
if (!is.list(x)) {
return(x)
}
n_col <- length(x)
if (n_col == 0) {
return(list())
}
n_row <- length(x[[1]])
if (n_row == 0) {
return(list())
}
out <- vector("list", length = n_row)
col_seq <- seq.int(n_col, 1)

vals <- vector("list", length = n_col)
names(vals) <- names(x)

for (row in seq.int(1, n_row)) {
for (col in col_seq) {
vals[col] <- (
if (length(x[[col]]) < n_row) {
list(rep_len(x[[col]], n_row)[[row]])
} else {
list(x[[col]][[row]])
})
}
out[[row]] <- vals
}
names(out) <- names(x[[1]])
return(out)
}
Loading