Deduped some code in val.cc into upsert_replacement_func.
Deduped some code in val.cc into upsert_replacement_func.

AntouanK/rethinkdb,captainpete/rethinkdb,yakovenkodenis/rethinkdb,mcanthony/rethinkdb,niieani/rethinkdb,spblightadv/rethinkdb,robertjpayne/rethinkdb,AntouanK/rethinkdb,losywee/rethinkdb,marshall007/rethinkdb,sbusso/rethinkdb,urandu/rethinkdb,Qinusty/rethinkdb,victorbriz/rethinkdb,urandu/rethinkdb,elkingtonmcb/rethinkdb,sontek/rethinkdb,catroot/rethinkdb,bchavez/rethinkdb,lenstr/rethinkdb,JackieXie168/rethinkdb,alash3al/rethinkdb,spblightadv/rethinkdb,gavioto/rethinkdb,wkennington/rethinkdb,ayumilong/rethinkdb,Qinusty/rethinkdb,alash3al/rethinkdb,spblightadv/rethinkdb,yakovenkodenis/rethinkdb,wojons/rethinkdb,tempbottle/rethinkdb,gdi2290/rethinkdb,sontek/rethinkdb,jesseditson/rethinkdb,gavioto/rethinkdb,bpradipt/rethinkdb,sbusso/rethinkdb,Qinusty/rethinkdb,eliangidoni/rethinkdb,greyhwndz/rethinkdb,rrampage/rethinkdb,mcanthony/rethinkdb,jmptrader/rethinkdb,losywee/rethinkdb,mbroadst/rethinkdb,rrampage/rethinkdb,eliangidoni/rethinkdb,eliangidoni/rethinkdb,spblightadv/rethinkdb,wojons/rethinkdb,yaolinz/rethinkdb,bpradipt/rethinkdb,Qinusty/rethinkdb,losywee/rethinkdb,grandquista/rethinkdb,mquandalle/rethinkdb,KSanthanam/rethinkdb,KSanthanam/rethinkdb,alash3al/rethinkdb,scripni/rethinkdb,yaolinz/rethinkdb,lenstr/rethinkdb,scripni/rethinkdb,gavioto/rethinkdb,jmptrader/rethinkdb,robertjpayne/rethinkdb,wojons/rethinkdb,AntouanK/rethinkdb,yaolinz/rethinkdb,alash3al/rethinkdb,catroot/rethinkdb,victorbriz/rethinkdb,jmptrader/rethinkdb,mcanthony/rethinkdb,ajose01/rethinkdb,gdi2290/rethinkdb,bpradipt/rethinkdb,sontek/rethinkdb,RubenKelevra/rethinkdb,ajose01/rethinkdb,Wilbeibi/rethinkdb,spblightadv/rethinkdb,wkennington/rethinkdb,KSanthanam/rethinkdb,sontek/rethinkdb,eliangidoni/rethinkdb,yakovenkodenis/rethinkdb,mquandalle/rethinkdb,lenstr/rethinkdb,mbroadst/rethinkdb,matthaywardwebdesign/rethinkdb,mquandalle/rethinkdb,gavioto/rethinkdb,mcanthony/rethinkdb,Qinusty/rethinkdb,bpradipt/rethinkdb,wkennington/rethinkdb,pap/rethinkdb,gdi2290/rethinkdb,sebadiaz/rethinkdb,bpradipt/rethinkdb,sbusso/rethinkdb,losywee/rethinkdb,RubenKelevra/rethinkdb,gdi2290/rethinkdb,Wilbeibi/rethinkdb,niieani/rethinkdb,grandquista/rethinkdb,ayumilong/rethinkdb,wojons/rethinkdb,robertjpayne/rethinkdb,jesseditson/rethinkdb,mbroadst/rethinkdb,AntouanK/rethinkdb,spblightadv/rethinkdb,jesseditson/rethinkdb,Qinusty/rethinkdb,sebadiaz/rethinkdb,niieani/rethinkdb,dparnell/rethinkdb,dparnell/rethinkdb,JackieXie168/rethinkdb,sontek/rethinkdb,matthaywardwebdesign/rethinkdb,grandquista/rethinkdb,rrampage/rethinkdb,captainpete/rethinkdb,alash3al/rethinkdb,victorbriz/rethinkdb,matthaywardwebdesign/rethinkdb,dparnell/rethinkdb,bchavez/rethinkdb,catroot/rethinkdb,greyhwndz/rethinkdb,elkingtonmcb/rethinkdb,sbusso/rethinkdb,elkingtonmcb/rethinkdb,matthaywardwebdesign/rethinkdb,yaolinz/rethinkdb,marshall007/rethinkdb,jesseditson/rethinkdb,sebadiaz/rethinkdb,wojons/rethinkdb,marshall007/rethinkdb,4talesa/rethinkdb,yakovenkodenis/rethinkdb,alash3al/rethinkdb,catroot/rethinkdb,gavioto/rethinkdb,mcanthony/rethinkdb,ajose01/rethinkdb,urandu/rethinkdb,jmptrader/rethinkdb,wkennington/rethinkdb,grandquista/rethinkdb,scripni/rethinkdb,sbusso/rethinkdb,dparnell/rethinkdb,sontek/rethinkdb,rrampage/rethinkdb,4talesa/rethinkdb,RubenKelevra/rethinkdb,lenstr/rethinkdb,mbroadst/rethinkdb,grandquista/rethinkdb,pap/rethinkdb,Wilbeibi/rethinkdb,captainpete/rethinkdb,JackieXie168/rethinkdb,Wilbeibi/rethinkdb,jmptrader/rethinkdb,victorbriz/rethinkdb,catroot/rethinkdb,urandu/rethinkdb,jesseditson/rethinkdb,dparnell/rethinkdb,matthaywardwebdesign/rethinkdb,mbroadst/rethinkdb,Qinusty/rethinkdb,eliangidoni/rethinkdb,AntouanK/rethinkdb,alash3al/rethinkdb,scripni/rethinkdb,elkingtonmcb/rethinkdb,gavioto/rethinkdb,dparnell/rethinkdb,Wilbeibi/rethinkdb,sebadiaz/rethinkdb,wojons/rethinkdb,yakovenkodenis/rethinkdb,AntouanK/rethinkdb,4talesa/rethinkdb,catroot/rethinkdb,alash3al/rethinkdb,yaolinz/rethinkdb,losywee/rethinkdb,sbusso/rethinkdb,captainpete/rethinkdb,jesseditson/rethinkdb,RubenKelevra/rethinkdb,jesseditson/rethinkdb,JackieXie168/rethinkdb,bpradipt/rethinkdb,wojons/rethinkdb,greyhwndz/rethinkdb,tempbottle/rethinkdb,urandu/rethinkdb,wujf/rethinkdb,elkingtonmcb/rethinkdb,lenstr/rethinkdb,catroot/rethinkdb,KSanthanam/rethinkdb,bchavez/rethinkdb,dparnell/rethinkdb,greyhwndz/rethinkdb,scripni/rethinkdb,eliangidoni/rethinkdb,sebadiaz/rethinkdb,urandu/rethinkdb,ajose01/rethinkdb,greyhwndz/rethinkdb,KSanthanam/rethinkdb,wkennington/rethinkdb,mcanthony/rethinkdb,4talesa/rethinkdb,rrampage/rethinkdb,4talesa/rethinkdb,scripni/rethinkdb,bpradipt/rethinkdb,ayumilong/rethinkdb,dparnell/rethinkdb,marshall007/rethinkdb,losywee/rethinkdb,wujf/rethinkdb,pap/rethinkdb,mquandalle/rethinkdb,JackieXie168/rethinkdb,captainpete/rethinkdb,wkennington/rethinkdb,grandquista/rethinkdb,grandquista/rethinkdb,KSanthanam/rethinkdb,grandquista/rethinkdb,RubenKelevra/rethinkdb,matthaywardwebdesign/rethinkdb,JackieXie168/rethinkdb,urandu/rethinkdb,mquandalle/rethinkdb,robertjpayne/rethinkdb,wkennington/rethinkdb,4talesa/rethinkdb,spblightadv/rethinkdb,matthaywardwebdesign/rethinkdb,AntouanK/rethinkdb,greyhwndz/rethinkdb,KSanthanam/rethinkdb,pap/rethinkdb,gdi2290/rethinkdb,wujf/rethinkdb,pap/rethinkdb,scripni/rethinkdb,RubenKelevra/rethinkdb,niieani/rethinkdb,sebadiaz/rethinkdb,rrampage/rethinkdb,bchavez/rethinkdb,bchavez/rethinkdb,greyhwndz/rethinkdb,ajose01/rethinkdb,yaolinz/rethinkdb,robertjpayne/rethinkdb,gavioto/rethinkdb,wujf/rethinkdb,tempbottle/rethinkdb,RubenKelevra/rethinkdb,eliangidoni/rethinkdb,mbroadst/rethinkdb,yaolinz/rethinkdb,bchavez/rethinkdb,rrampage/rethinkdb,gdi2290/rethinkdb,AntouanK/rethinkdb,mbroadst/rethinkdb,jmptrader/rethinkdb,tempbottle/rethinkdb,sontek/rethinkdb,mquandalle/rethinkdb,wujf/rethinkdb,mquandalle/rethinkdb,captainpete/rethinkdb,lenstr/rethinkdb,spblightadv/rethinkdb,JackieXie168/rethinkdb,wujf/rethinkdb,marshall007/rethinkdb,bchavez/rethinkdb,mbroadst/rethinkdb,greyhwndz/rethinkdb,mcanthony/rethinkdb,ayumilong/rethinkdb,sbusso/rethinkdb,yaolinz/rethinkdb,niieani/rethinkdb,tempbottle/rethinkdb,ayumilong/rethinkdb,mbroadst/rethinkdb,robertjpayne/rethinkdb,ayumilong/rethinkdb,robertjpayne/rethinkdb,bpradipt/rethinkdb,elkingtonmcb/rethinkdb,JackieXie168/rethinkdb,ayumilong/rethinkdb,sbusso/rethinkdb,urandu/rethinkdb,JackieXie168/rethinkdb,tempbottle/rethinkdb,gdi2290/rethinkdb,4talesa/rethinkdb,eliangidoni/rethinkdb,pap/rethinkdb,pap/rethinkdb,jmptrader/rethinkdb,niieani/rethinkdb,grandquista/rethinkdb,rrampage/rethinkdb,lenstr/rethinkdb,victorbriz/rethinkdb,lenstr/rethinkdb,ajose01/rethinkdb,yakovenkodenis/rethinkdb,victorbriz/rethinkdb,scripni/rethinkdb,losywee/rethinkdb,yakovenkodenis/rethinkdb,Wilbeibi/rethinkdb,captainpete/rethinkdb,captainpete/rethinkdb,mcanthony/rethinkdb,Qinusty/rethinkdb,Wilbeibi/rethinkdb,niieani/rethinkdb,sontek/rethinkdb,robertjpayne/rethinkdb,ayumilong/rethinkdb,sebadiaz/rethinkdb,ajose01/rethinkdb,wujf/rethinkdb,sebadiaz/rethinkdb,gavioto/rethinkdb,victorbriz/rethinkdb,mquandalle/rethinkdb,elkingtonmcb/rethinkdb,bchavez/rethinkdb,Wilbeibi/rethinkdb,losywee/rethinkdb,KSanthanam/rethinkdb,Qinusty/rethinkdb,4talesa/rethinkdb,marshall007/rethinkdb,bchavez/rethinkdb,bpradipt/rethinkdb,catroot/rethinkdb,marshall007/rethinkdb,ajose01/rethinkdb,wojons/rethinkdb,dparnell/rethinkdb,matthaywardwebdesign/rethinkdb,elkingtonmcb/rethinkdb,tempbottle/rethinkdb,tempbottle/rethinkdb,jesseditson/rethinkdb,eliangidoni/rethinkdb,marshall007/rethinkdb,wkennington/rethinkdb,pap/rethinkdb,victorbriz/rethinkdb,jmptrader/rethinkdb,yakovenkodenis/rethinkdb,robertjpayne/rethinkdb,niieani/rethinkdb,RubenKelevra/rethinkdb