static Variant preg_replace_callback_array_impl( const Variant& patterns_and_callbacks, const Array& subjects, int limit, VRefParam count) { Array ret = Array::Create(); auto key = 0; auto total_replacement_count = 0; for (ArrayIter s_iter(subjects); s_iter; ++s_iter) { assert(s_iter.second().isString()); auto subj = s_iter.second(); for (ArrayIter pc_iter(patterns_and_callbacks.toArray()); pc_iter; ++pc_iter) { Variant pattern(pc_iter.first()); assert(pattern.isString()); Variant callback(pc_iter.second()); subj = HHVM_FN(preg_replace_callback)(pattern, callback, subj, limit, count); // If we got an error on the replacement, the subject will be null, // and then we will return null. if (subj.isNull()) { return init_null(); } if (count.isReferenced()) { total_replacement_count += count.toInt64(); } } ret.add(key++, subj); } // If count was passed in as an explicit reference, we will assign it to our // total replacement count; otherwise, count will just remained unassigned count.assignIfRef(total_replacement_count); // If there were no replacements (i.e., matches) return original subject(s) if (ret.empty()) { return subjects; } return ret; }
bool RakeResults<SampleSeq>::copy_into(FwdIter iter, FwdIter end, typename SampleSeq::PrivateMemberAccess& received_data_p) { typedef typename SampleSeq::value_type Sample; typedef OPENDDS_MAP(SubscriptionInstance*, InstanceData) InstanceMap; InstanceMap inst_map; typedef OPENDDS_SET(SubscriptionInstance*) InstanceSet; InstanceSet released_instances; for (CORBA::ULong idx = 0; iter != end && idx < max_samples_; ++idx, ++iter) { // 1. Populate the Received Data sequence ReceivedDataElement* rde = iter->rde_; if (received_data_.maximum() != 0) { if (rde->registered_data_ == 0) { received_data_p.assign_sample(idx, Sample()); } else { received_data_p.assign_sample(idx, *static_cast<Sample*>(rde->registered_data_)); } } else { received_data_p.assign_ptr(idx, rde); } // 2. Per-sample SampleInfo (not the three *_rank variables) and state SubscriptionInstance& inst = *iter->si_; inst.instance_state_.sample_info(info_seq_[idx], rde); rde->sample_state_ = DDS::READ_SAMPLE_STATE; // 3. Record some info about per-instance SampleInfo (*_rank) so that // we can fill in the ranks after the loop has completed std::pair<typename InstanceMap::iterator, bool> result = inst_map.insert(std::make_pair(&inst, InstanceData())); InstanceData& id = result.first->second; if (result.second) { // first time we've seen this Instance ReceivedDataElement& mrs = *inst.rcvd_samples_.tail_; id.MRS_disposed_gc_ = static_cast<CORBA::Long>(mrs.disposed_generation_count_); id.MRS_nowriters_gc_ = static_cast<CORBA::Long>(mrs.no_writers_generation_count_); } if (iter->index_in_instance_ >= id.MRSIC_index_) { id.MRSIC_index_ = iter->index_in_instance_; id.MRSIC_disposed_gc_ = static_cast<CORBA::Long>(rde->disposed_generation_count_); id.MRSIC_nowriters_gc_ = static_cast<CORBA::Long>(rde->no_writers_generation_count_); } if (!id.most_recent_generation_) { id.most_recent_generation_ = inst.instance_state_.most_recent_generation(rde); } id.sampleinfo_positions_.push_back(idx); // 4. Take if (oper_ == DDS_OPERATION_TAKE) { // If removing the sample releases it if (inst.rcvd_samples_.remove(rde)) { // Prevent access of the SampleInfo, below released_instances.insert(&inst); } this->reader_->dec_ref_data_element(rde); } } // Fill in the *_ranks in the SampleInfo, and set instance state (mrg) for (typename InstanceMap::iterator i_iter(inst_map.begin()), i_end(inst_map.end()); i_iter != i_end; ++i_iter) { InstanceData& id = i_iter->second; { // Danger, limit visibility of inst SubscriptionInstance& inst = *i_iter->first; // If this instance has not been released if (released_instances.find(&inst) == released_instances.end()) { if (id.most_recent_generation_) { inst.instance_state_.accessed(); } } } CORBA::Long sample_rank = static_cast<CORBA::Long>(id.sampleinfo_positions_.size()); for (IndexList::iterator s_iter(id.sampleinfo_positions_.begin()), s_end(id.sampleinfo_positions_.end()); s_iter != s_end; ++s_iter) { DDS::SampleInfo& si = info_seq_[*s_iter]; si.sample_rank = --sample_rank; si.generation_rank = id.MRSIC_disposed_gc_ + id.MRSIC_nowriters_gc_ - si.generation_rank; si.absolute_generation_rank = id.MRS_disposed_gc_ + id.MRS_nowriters_gc_ - si.absolute_generation_rank; } } return true; }