Skip to content

Commit 04e9ef3

Browse files
committed
avoid dynamic allocations by using uti static freelist resource, other small cleanups
1 parent dd8d3bd commit 04e9ef3

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

include/command.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#include <types.hpp>
1010

11-
#include <uti/container/vector.hpp>
12-
1311
#define FLT_CMD_MAX_COUNT 4
1412
#define FLT_CMD_MAX_LEN 8
1513

@@ -24,8 +22,8 @@ struct report
2422
} ;
2523

2624

27-
IOReturn send_report ( hid_device const & device, report const & report ) ;
28-
IOReturn send_report ( hid_device const & device, uti::vector< report > const & reports ) ;
25+
IOReturn send_report ( hid_device const & device, report const & report ) ;
26+
IOReturn send_report ( hid_device const & device, vector< report > const & reports ) ;
2927

3028

3129
} // namespace flt

include/device.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#include <types.hpp>
1010

11-
#include <uti/container/vector.hpp>
12-
1311
#include <iterator>
1412
#include <algorithm>
1513

@@ -34,9 +32,9 @@ class device_manager
3432
public:
3533
device_manager () noexcept : hid_manager_( _create_hid_manager() ) {}
3634

37-
auto list_devices () -> uti::vector< hid_device >
35+
auto list_devices () -> vector< hid_device >
3836
{
39-
uti::vector< hid_device > dev_set ;
37+
vector< hid_device > dev_set ;
4038

4139
CFSetRef device_setref = IOHIDManagerCopyDevices( hid_manager_ ) ;
4240
CFIndex count = CFSetGetCount( device_setref ) ;
@@ -61,10 +59,10 @@ class device_manager
6159
return dev_set ;
6260
}
6361

64-
auto find_known_wheels () -> uti::vector< hid_device >
62+
auto find_known_wheels () -> vector< hid_device >
6563
{
66-
uti::vector< hid_device > dev_set = list_devices() ;
67-
uti::vector< hid_device > wheels ;
64+
vector< hid_device > dev_set = list_devices() ;
65+
vector< hid_device > wheels ;
6866

6967
std::copy_if( dev_set.begin(), dev_set.end(), std::back_inserter( wheels ),
7068
[ & ]( hid_device const & dev )

include/types.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <uti/type/traits.hpp>
1010
#include <uti/container/array.hpp>
11+
#include <uti/container/vector.hpp>
12+
#include <uti/allocator/freelist_resource.hpp>
1113

1214
#include <IOKit/hid/IOHIDDevice.h>
1315
#include <IOKit/hid/IOHIDManager.h>
@@ -21,6 +23,9 @@ using device_id_t = uti::u32_t ;
2123
using hid_device_t = __IOHIDDevice ;
2224
using hid_manager_t = __IOHIDManager ;
2325

26+
template< typename T >
27+
using vector = uti::vector< T, uti::allocator< T, uti::static_freelist_resource< 1024 * 1024 > > > ;
28+
2429

2530
struct hid_device
2631
{

source/command.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ IOReturn send_report ( hid_device const & device, report const & report )
2020
return result ;
2121
}
2222

23-
IOReturn send_report ( hid_device const & device, uti::vector< report > const & reports )
23+
IOReturn send_report ( hid_device const & device, vector< report > const & reports )
2424
{
2525
IOReturn result ;
2626

0 commit comments

Comments
 (0)