mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
Generalize swapWithArray
Conflicts: Subtrees/beast/TODO.txt
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
Write code in a clear, self-documenting style but use comments where necessary.
|
||||
Use Test Driven Development. It encourages designing interfaces first, before implementation.
|
||||
Don't Repeat Yourself, <20>D.R.Y.<2E>. Put redundant code in a class so it can be re-used and unit tested.
|
||||
Expose as little of a class as possible. Prefer private over protected. Prefer protected over public. The smaller the interface footprint, the easier it is to write unit tests and comprehend the operation of the class. This is the Interface Segregation Principle.
|
||||
Use language constants (enum or static const) with descriptive names instead of hard-coded <20>magic numbers.<2E>
|
||||
Make classes depend on as few external classes or routines as possible. Ideally, no dependencies.
|
||||
Don't limit flexibility of parameters by forcing the caller to use specific types where general types would work.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
# Coding Standards
|
||||
@@ -175,6 +183,9 @@ overlooked. Blank lines are used to separate code into "paragraphs."
|
||||
|
||||
## Miscellaneous
|
||||
|
||||
* Constrain the scope of identifiers to the smallest area that needs it. Consider
|
||||
using nested classes or classes inside functions, if doing so will expose less
|
||||
interface and implementation overall.
|
||||
* `goto` statements should not be used at all, even if the alternative is
|
||||
more verbose code. The only exception is when implementing an algorithm in
|
||||
a function as a state machine.
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
BEAST TODO
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
- Implement HardenedHashFunctions
|
||||
- HashMap work:
|
||||
- Add unit test
|
||||
- Return size_t from hash function, take out upperLimit, move mod % to caller
|
||||
- Make hash function a functor using operator()
|
||||
- Implement HardenedHashFunctions
|
||||
|
||||
- Set sqlite thread safety model to '2' in beast_sqlite
|
||||
|
||||
|
||||
@@ -571,10 +571,11 @@ public:
|
||||
If you need to exchange two arrays, this is vastly quicker than using copy-by-value
|
||||
because it just swaps their internal pointers.
|
||||
*/
|
||||
void swapWithArray (Array& otherArray) noexcept
|
||||
template <class OtherArrayType>
|
||||
void swapWithArray (OtherArrayType& otherArray) noexcept
|
||||
{
|
||||
const ScopedLockType lock1 (getLock());
|
||||
const ScopedLockType lock2 (otherArray.getLock());
|
||||
const typename OtherArrayType::ScopedLockType lock2 (otherArray.getLock());
|
||||
|
||||
data.swapWith (otherArray.data);
|
||||
std::swap (numUsed, otherArray.numUsed);
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
|
||||
//==============================================================================
|
||||
/** Clears the array, optionally deleting the objects inside it first. */
|
||||
void clear (const bool deleteObjects = true)
|
||||
void clear (bool deleteObjects = true)
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
|
||||
@@ -101,14 +101,19 @@ public:
|
||||
numUsed = 0;
|
||||
}
|
||||
|
||||
/** Removes all elements from the array without freeing the array's allocated storage.
|
||||
/** Clears the array, optionally deleting the objects inside it first.
|
||||
|
||||
The array's allocated storage is preserved.
|
||||
|
||||
@see clear
|
||||
*/
|
||||
void clearQuick()
|
||||
void clearQuick(bool deleteObjects = true)
|
||||
{
|
||||
const ScopedLockType lock (getLock());
|
||||
deleteAllElements();
|
||||
|
||||
if (deleteObjects)
|
||||
deleteAllObjects();
|
||||
|
||||
numUsed = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef BEAST_REFERENCECOUNTEDARRAY_BEASTHEADER
|
||||
#define BEAST_REFERENCECOUNTEDARRAY_BEASTHEADER
|
||||
#ifndef BEAST_SHAREDOBJECTARRAY_H_INCLUDED
|
||||
#define BEAST_SHAREDOBJECTARRAY_H_INCLUDED
|
||||
|
||||
#include "../memory/beast_SharedObject.h"
|
||||
#include "beast_ArrayAllocationBase.h"
|
||||
@@ -740,10 +740,11 @@ public:
|
||||
If you need to exchange two arrays, this is vastly quicker than using copy-by-value
|
||||
because it just swaps their internal pointers.
|
||||
*/
|
||||
void swapWithArray (SharedObjectArray& otherArray) noexcept
|
||||
template <class OtherArrayType>
|
||||
void swapWithArray (OtherArrayType& otherArray) noexcept
|
||||
{
|
||||
const ScopedLockType lock1 (getLock());
|
||||
const ScopedLockType lock2 (otherArray.getLock());
|
||||
const typename OtherArrayType::ScopedLockType lock2 (otherArray.getLock());
|
||||
|
||||
data.swapWith (otherArray.data);
|
||||
std::swap (numUsed, otherArray.numUsed);
|
||||
|
||||
Reference in New Issue
Block a user