mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Don't include heavy STL headers like <algorithm> in header files
This provides a considerable compilation time reduction and most of these were just using std::copy/fill which can be replaced by memcpy/memset, as all of their uses were applied to POD types
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#define _GLIBCXX_USE_NANOSLEEP
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <cstdint>
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#define TINS_BOOTP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
@@ -268,15 +267,14 @@ public:
|
||||
*/
|
||||
template<size_t n>
|
||||
void chaddr(const HWAddress<n>& new_chaddr) {
|
||||
// Copy the new addr
|
||||
uint8_t* end = std::copy(
|
||||
new_chaddr.begin(),
|
||||
new_chaddr.begin() + std::min(n, sizeof(bootp_.chaddr)),
|
||||
bootp_.chaddr
|
||||
);
|
||||
// Fill what's left with zeros
|
||||
if (end < bootp_.chaddr + chaddr_type::address_size) {
|
||||
std::fill(end, bootp_.chaddr + chaddr_type::address_size, 0);
|
||||
size_t copy_threshold = std::min(n, sizeof(bootp_.chaddr));
|
||||
for (size_t i = 0; i < copy_threshold; ++i) {
|
||||
if (i < copy_threshold) {
|
||||
bootp_.chaddr[i] = new_chaddr[i];
|
||||
}
|
||||
else {
|
||||
bootp_.chaddr[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@
|
||||
#if TINS_IS_CXX11
|
||||
#include <type_traits>
|
||||
#endif
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include "constants.h"
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#define TINS_IPADDRESS_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iosfwd>
|
||||
#include <stdint.h>
|
||||
#include "cxxstd.h"
|
||||
#include "macros.h"
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <iosfwd>
|
||||
#include <stdint.h>
|
||||
#include "cxxstd.h"
|
||||
#include "macros.h"
|
||||
@@ -203,10 +204,7 @@ public:
|
||||
* \param addr The parameter to be written.
|
||||
* \return std::ostream& pointing to the os parameter.
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, const IPv6Address& addr) {
|
||||
return os << addr.to_string();
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const IPv6Address& addr);
|
||||
|
||||
/**
|
||||
* Applies a mask to an address
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "exceptions.h"
|
||||
#include "ip_address.h"
|
||||
@@ -213,7 +212,7 @@ public:
|
||||
if (TINS_UNLIKELY(size_ < length)) {
|
||||
throw serialization_error();
|
||||
}
|
||||
std::copy(start, end, buffer_);
|
||||
std::memcpy(buffer_, &*start, length);
|
||||
skip(length);
|
||||
}
|
||||
|
||||
@@ -238,7 +237,7 @@ public:
|
||||
if (TINS_UNLIKELY(size_ < size)) {
|
||||
throw serialization_error();
|
||||
}
|
||||
std::fill(buffer_, buffer_ + size, value);
|
||||
std::memset(buffer_, value, size);
|
||||
skip(size);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#ifndef TINS_PDU_CACHER_H
|
||||
#define TINS_PDU_CACHER_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
|
||||
@@ -148,7 +148,7 @@ private:
|
||||
if (cached_serialization_.size() != total_sz) {
|
||||
cached_serialization_ = cached_.serialize();
|
||||
}
|
||||
std::copy(cached_serialization_.begin(), cached_serialization_.end(), buffer);
|
||||
std::memcpy(buffer, &*cached_serialization_.begin(), cached_serialization_.size());
|
||||
}
|
||||
|
||||
cached_type cached_;
|
||||
|
||||
@@ -33,9 +33,7 @@
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <stdint.h>
|
||||
#include "exceptions.h"
|
||||
#include "endianness.h"
|
||||
@@ -375,11 +373,7 @@ public:
|
||||
rhs.real_size_ = 0;
|
||||
}
|
||||
else {
|
||||
std::copy(
|
||||
rhs.data_ptr(),
|
||||
rhs.data_ptr() + rhs.data_size(),
|
||||
payload_.small_buffer
|
||||
);
|
||||
std::memcpy(payload_.small_buffer, rhs.data_ptr(), rhs.data_size());
|
||||
}
|
||||
return* this;
|
||||
}
|
||||
@@ -516,16 +510,12 @@ private:
|
||||
template<typename ForwardIterator>
|
||||
void set_payload_contents(ForwardIterator start, ForwardIterator end) {
|
||||
size_t total_size = std::distance(start, end);
|
||||
if (total_size > std::numeric_limits<uint16_t>::max()) {
|
||||
if (total_size > 65535) {
|
||||
throw option_payload_too_large();
|
||||
}
|
||||
real_size_ = static_cast<uint16_t>(total_size);
|
||||
if (real_size_ <= small_buffer_size) {
|
||||
std::copy(
|
||||
start,
|
||||
end,
|
||||
payload_.small_buffer
|
||||
);
|
||||
std::memcpy(payload_.small_buffer, &*start, total_size);
|
||||
}
|
||||
else {
|
||||
payload_.big_buffer_ptr = new data_type[real_size_];
|
||||
|
||||
@@ -48,7 +48,7 @@ class NetworkInterface;
|
||||
class PacketSender;
|
||||
class PDU;
|
||||
class IPv6Address;
|
||||
template <size_t n, typename Storage>
|
||||
template <size_t n>
|
||||
class HWAddress;
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "endianness.h"
|
||||
#include "dhcp.h"
|
||||
#include "ethernetII.h"
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#ifdef TINS_HAVE_DOT11
|
||||
|
||||
#include <algorithm>
|
||||
#include "dot11/dot11_data.h"
|
||||
|
||||
using std::max_element;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "icmpv6.h"
|
||||
#include "ipv6.h"
|
||||
#include "rawpdu.h"
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#endif // _WIN32
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include "ip_address.h"
|
||||
#include "endianness.h"
|
||||
#include "address_range.h"
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include "macros.h"
|
||||
#ifndef _WIN32
|
||||
#include <arpa/inet.h>
|
||||
@@ -38,14 +37,17 @@
|
||||
#include <ws2tcpip.h>
|
||||
#include <mstcpip.h>
|
||||
#endif
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include "ipv6_address.h"
|
||||
#include "address_range.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
using std::fill;
|
||||
using std::string;
|
||||
using std::ostream;
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -132,6 +134,10 @@ bool IPv6Address::is_multicast() const {
|
||||
return multicast_range.contains(*this);
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream& os, const IPv6Address& addr) {
|
||||
return os << addr.to_string();
|
||||
}
|
||||
|
||||
IPv6Address operator&(const IPv6Address& lhs, const IPv6Address& rhs) {
|
||||
IPv6Address output = lhs;
|
||||
IPv6Address::iterator addr_iter = output.begin();
|
||||
|
||||
Reference in New Issue
Block a user