-
Notifications
You must be signed in to change notification settings - Fork 137
[Storage] Implement List API across Android, iOS, and Desktop #1841
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
Changes from 1 commit
88a564c
7d25ca8
ded065f
a42d859
38d793d
0d2600b
f1f5886
c858561
6853b2a
d09f348
eb8a622
bab9b6d
fd71103
8c76073
1a66acd
de2364b
8054e69
93622c4
1e6569e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Copyright 2024 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "storage/src/include/firebase/storage/list_result.h" | ||
| #include "storage/src/common/list_result_internal.h" | ||
|
|
||
| namespace firebase { | ||
| namespace storage { | ||
|
|
||
| StorageListResult::StorageListResult() : internal_(nullptr) {} | ||
|
|
||
| StorageListResult::~StorageListResult() { | ||
| delete internal_; | ||
| internal_ = nullptr; | ||
| } | ||
|
|
||
| StorageListResult::StorageListResult(const StorageListResult& other) | ||
| : internal_(other.internal_ ? new internal::StorageListResultInternal(*other.internal_) : nullptr) {} | ||
|
|
||
| StorageListResult& StorageListResult::operator=(const StorageListResult& other) { | ||
| if (this == &other) { | ||
| return *this; | ||
| } | ||
| delete internal_; | ||
| internal_ = other.internal_ ? new internal::StorageListResultInternal(*other.internal_) : nullptr; | ||
| return *this; | ||
| } | ||
|
|
||
| #if defined(FIREBASE_USE_MOVE_OPERATORS) || defined(DOXYGEN) | ||
| StorageListResult::StorageListResult(StorageListResult&& other) { | ||
| internal_ = other.internal_; | ||
| other.internal_ = nullptr; | ||
| } | ||
|
|
||
| StorageListResult& StorageListResult::operator=(StorageListResult&& other) { | ||
| if (this == &other) { | ||
| return *this; | ||
| } | ||
| delete internal_; | ||
| internal_ = other.internal_; | ||
| other.internal_ = nullptr; | ||
| return *this; | ||
| } | ||
| #endif // defined(FIREBASE_USE_MOVE_OPERATORS) || defined(DOXYGEN) | ||
|
|
||
| const std::vector<StorageReference>& StorageListResult::prefixes() const { | ||
| static const std::vector<StorageReference> empty_prefixes; | ||
| return internal_ ? internal_->prefixes() : empty_prefixes; | ||
| } | ||
|
|
||
| const std::vector<StorageReference>& StorageListResult::items() const { | ||
| static const std::vector<StorageReference> empty_items; | ||
| return internal_ ? internal_->items() : empty_items; | ||
| } | ||
|
|
||
| const char* StorageListResult::next_page_token() const { | ||
| return internal_ ? internal_->next_page_token() : nullptr; | ||
| } | ||
|
|
||
| StorageListResult::StorageListResult(internal::StorageListResultInternal* internal) | ||
| : internal_(internal) {} | ||
|
|
||
| } // namespace storage | ||
| } // namespace firebase |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||||
| // Copyright 2024 Google LLC | ||||||||||||||||||
| // | ||||||||||||||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||
| // you may not use this file except in compliance with the License. | ||||||||||||||||||
| // You may obtain a copy of the License at | ||||||||||||||||||
| // | ||||||||||||||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||
| // | ||||||||||||||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||
| // See the License for the specific language governing permissions and | ||||||||||||||||||
| // limitations under the License. | ||||||||||||||||||
|
|
||||||||||||||||||
| #ifndef FIREBASE_STORAGE_SRC_COMMON_LIST_RESULT_INTERNAL_H_ | ||||||||||||||||||
| #define FIREBASE_STORAGE_SRC_COMMON_LIST_RESULT_INTERNAL_H_ | ||||||||||||||||||
|
|
||||||||||||||||||
| #include <string> | ||||||||||||||||||
| #include <vector> | ||||||||||||||||||
|
|
||||||||||||||||||
| #include "storage/src/include/firebase/storage/storage_reference.h" | ||||||||||||||||||
|
|
||||||||||||||||||
| namespace firebase { | ||||||||||||||||||
| namespace storage { | ||||||||||||||||||
| namespace internal { | ||||||||||||||||||
|
|
||||||||||||||||||
| /// @brief Internal representation of a StorageListResult. | ||||||||||||||||||
| class StorageListResultInternal { | ||||||||||||||||||
| public: | ||||||||||||||||||
| StorageListResultInternal() {} | ||||||||||||||||||
| StorageListResultInternal(const std::vector<StorageReference>& prefixes, | ||||||||||||||||||
| const std::vector<StorageReference>& items, | ||||||||||||||||||
| const std::string& next_page_token) | ||||||||||||||||||
| : prefixes_(prefixes), items_(items), next_page_token_(next_page_token) {} | ||||||||||||||||||
|
Comment on lines
+31
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constructor copies its arguments, which can be inefficient. Since the call sites are passing temporary local variables, it's better to move the data instead of copying it. By changing the constructor to take its arguments by value, you can then use
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| StorageListResultInternal(const StorageListResultInternal& other) | ||||||||||||||||||
| : prefixes_(other.prefixes_), | ||||||||||||||||||
| items_(other.items_), | ||||||||||||||||||
| next_page_token_(other.next_page_token_) {} | ||||||||||||||||||
|
|
||||||||||||||||||
| const std::vector<StorageReference>& prefixes() const { return prefixes_; } | ||||||||||||||||||
| const std::vector<StorageReference>& items() const { return items_; } | ||||||||||||||||||
| const char* next_page_token() const { | ||||||||||||||||||
| return next_page_token_.empty() ? nullptr : next_page_token_.c_str(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private: | ||||||||||||||||||
| std::vector<StorageReference> prefixes_; | ||||||||||||||||||
| std::vector<StorageReference> items_; | ||||||||||||||||||
| std::string next_page_token_; | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| } // namespace internal | ||||||||||||||||||
| } // namespace storage | ||||||||||||||||||
| } // namespace firebase | ||||||||||||||||||
|
|
||||||||||||||||||
| #endif // FIREBASE_STORAGE_SRC_COMMON_LIST_RESULT_INTERNAL_H_ | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve performance, use
std::moveto transfer ownership of the local variables to theStorageListResultInternalconstructor. This avoids unnecessary copies of the vectors and the string, as they are no longer needed in this scope. I've made a related suggestion to update the constructor to take advantage of this.