diff --git a/ac.h b/ac.h index b547b88..3b09ac3 100644 --- a/ac.h +++ b/ac.h @@ -4,7 +4,11 @@ extern "C" { #endif +#ifndef _MSC_VER #define AC_EXPORT __attribute__ ((visibility ("default"))) +#else +#define AC_EXPORT +#endif /* If the subject-string doesn't match any of the given patterns, "match_begin" * should be a negative; otherwise the substring of the subject-string, diff --git a/ac_fast.cxx b/ac_fast.cxx index 1cf145f..90991c1 100644 --- a/ac_fast.cxx +++ b/ac_fast.cxx @@ -11,7 +11,7 @@ AC_Converter::Calc_State_Sz(const ACS_State* s) const { if (sz < sizeof(AC_State)) sz = sizeof(AC_State); - uint32 align = __alignof__(dummy); + uint32 align = __alignof(dummy); sz = (sz + align - 1) & ~(align - 1); return sz; } @@ -35,14 +35,14 @@ AC_Converter::Alloc_Buffer() { root_goto_ofst = 0; // part 3: mapping of state's relative position. - unsigned align = __alignof__(AC_Ofst); + unsigned align = __alignof(AC_Ofst); sz = (sz + align - 1) & ~(align - 1); states_ofst_ofst = sz; sz += sizeof(AC_Ofst) * all_states.size(); // part 4: state's contents - align = __alignof__(AC_State); + align = __alignof(AC_State); sz = (sz + align - 1) & ~(align - 1); first_state_ofst = sz; @@ -82,7 +82,7 @@ AC_Converter::Populate_Root_Goto_Func(AC_Buffer* buf, uint32 new_id = 1; bool full_fantout = (goto_vect.size() == 255); if (likely(!full_fantout)) - bzero(root_gotos, 256*sizeof(InputTy)); + memset(root_gotos, 0, 256 * sizeof(InputTy)); for (GotoVect::iterator i = goto_vect.begin(), e = goto_vect.end(); i != e; i++, new_id++) { @@ -212,7 +212,14 @@ Get_State_Addr(unsigned char* buf_base, AC_Ofst* StateOfstVect, uint32 state_id) // 10+ benchmarks. It's still too early to say which one works better. // #if !defined(BS_MULTI_VER) -static bool __attribute__((always_inline)) inline + +#ifdef _MSC_VER +#define INLINE_FLAG inline __forceinline +#else +#define INLINE_FLAG inline __attribute__((always_inline)) +#endif + +static bool INLINE_FLAG Binary_Search_Input(InputTy* input_vect, int vect_len, InputTy input, int& idx) { if (vect_len <= 8) { for (int i = 0; i < vect_len; i++) { diff --git a/ac_slow.cxx b/ac_slow.cxx index cb3957a..ac06bbb 100644 --- a/ac_slow.cxx +++ b/ac_slow.cxx @@ -1,5 +1,4 @@ #include -#include // for bzero #include #include "ac_slow.hpp" #include "ac.h" @@ -13,7 +12,7 @@ ACS_Constructor::ACS_Constructor() : _next_node_id(1) { _root = new_state(); _root_char = new InputTy[256]; - bzero((void*)_root_char, 256); + memset((void*)_root_char, 0, 256 * sizeof(InputTy)); #ifdef VERIFY _pattern_buf = 0; diff --git a/ac_util.hpp b/ac_util.hpp index 0815193..e0d89ea 100644 --- a/ac_util.hpp +++ b/ac_util.hpp @@ -48,8 +48,13 @@ typedef unsigned char InputTy; #define ASSERT(c) ((void)0) #endif +#ifndef _MSC_VER #define likely(x) __builtin_expect((x),1) #define unlikely(x) __builtin_expect((x),0) +#else +#define likely(x) (x) +#define unlikely(x) (x) +#endif #ifndef offsetof #define offsetof(st, m) ((size_t)(&((st *)0)->m))